Copy wave and paste as new wave with arithmatic option
| supra | May 15, 2012 - 13:30 | ||
|---|---|---|---|
|
Hi a) How I can add checkboxes in the GUI to select +-x/ . #pragma rtGlobals=1 // Use modern global access method. Menu "Column Math" "Column MathA/1", copy22(0) End Function copy22(AorB) Variable AorB // 0 for A, 1 for B String tableName = WinName(0, 2,1) if (strlen(tableName) == 0) Abort "There are no tabels" endif GetSelection table, $tableName, 1 //Get selection row and column indices Variable startColumn = V_startCol //Index of first selected column Wave y2 = WaveRefindexed(tableName, startColumn, 1) Duplicate/O y2, wave0_y2 Variable term=1 Prompt term, "Enter parameter: " // Set prompt for XRange param DoPrompt "Enter parameter", term if (V_Flag) return -1 // User canceled endif wave0_y2 = wave0_y2 + term AppendToTable wave0_y2 End |
|||

Joined: 2009-01-06
Location: Switzerland
Have you looked at "Analysis -> Packages -> Wave Arithmetic" and the corresponding ipf, if this could be of any use?
Joined: 2011-03-14
Location: United States
The wave arithmetic package does this feature with graphs. You should be able to modify this code for tables if you really want to.
In regards to making a GUI, what you want is NewPanel.... not a prompt. Your GUI (Panel) would need the following:
Popupmenu, or Listbox, to select wave of interest
SetVariable to enter the X value
Checkboxes for Add, Subtract, Divide, etc.
Button to perform operation.
All of these are described in detail in the Manual.
Joined: 2011-08-10
Location: United States
Thanks for reply. I indeed tried to make a panel with one "Button"(butto0), Two checkbox ( check0 and check1 : say + and - operation) and one value display ( that does not make code in procedure but visible in panel ..why ? ..but the problem is I dont know how to associate the panel with the procedure. Say the "term" is the value display and if check the first checkbox (check0) it should do "wave0_y2 = wave0_y2 + term"
How should I do ..Can anybody help me ?
Joined: 2007-06-29
Location: United States
ValDisplay controls don't have action procedures because they are intended only for display. If you want something like ValDisplay, but user editable, use a SetVariable control.
A typical control panel to do something like this would have various controls to set up the conditions for the action you want (your checkboxes, etc.) and a button labelled "Apply" or "Do It" or "OK" or something along those lines. The action procedure for that button would then use ControlInfo to read the state of each of the controls in the panel, and perform the action as specified by all the control settings.
John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
Joined: 2011-08-10
Location: United States
Thanks for replying...
I tried to do something...but I have following problems
a) I tried to use the panel creation function
DoMyInputPanel()inside main calculation functioncopy22(AorB)and it gives error.a) I dont know how to define a procedure from a function ...I tried with the following but dont know whether it is logical to do it
Then in the button click procedure
Button button0,proc=CopySum, title="OK"it gives a error and says "even macro should have paranthesis".
(c) Also
wave0_y2 = wave0_y2 + term1gives a error about Global variable..and does not workMain code
-------------
Joined: 2007-06-29
Location: United States
DoMyInputPanel()inside main calculation functioncopy22(AorB)and it gives error.In general, "it gives error" isn't helpful. I copied your code into Igor and ran it- the error is "parameter not declared". That is because you put the call to DoMyInputPanel() before the declaration of AorB. Input parameters must be declared before anything else.
When I fixed that, there is still an error: term1 is never declared. It looks like the code isn't finished yet.
a) I dont know how to define a procedure from a function ...I tried with the following but dont know whether it is logical to do it
Then in the button click procedure
Button button0,proc=CopySum, title="OK"it gives a error and says "even macro should have paranthesis".
The correct way to do that would be "Proc CopySum()", but you don't want to do that. If you double-click the button (the panel must be in draw mode: Panel->Show Tools) you will get a Button Dialog. Click the New button next to the Procedure entry, a new dialog will appear with the skeleton of a button action procedure in correct form. Don't change the inputs to the skeleton function since action procedures must have the correct form for a given type of control. Now fill in the appropriate code inside the skeleton, like a call to your function copy22().
BUT- remove the call to DoMyInputPanel(). By the time the button is clicked, the panel already exists.
(c) Also
wave0_y2 = wave0_y2 + term1gives a error about Global variable..and does not workI mentioned above that term1 is never defined. You need to tell Igor what kind of object is in term1, make sure it exists before the function runs, and has valid contents.
Don't give up. I know it's being confusing and taking a lot of tries to get this going. But you're learning a lot, and the next time it will be a little easier.
John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
Joined: 2011-03-14
Location: United States
Your commands to create the panel look good. In regards to the button proc, change CopySum to the following.
While you do declare term1 to be a global variable, the other functions need to know what it is. Whenever term1 is used in another function of your procedure, it needs to be declared using
NVAR term1Joined: 2011-08-10
Location: United States
Thank you for your encouragement. I did able to do most of the thing like the way you said....except I dont know how to choose the chekbox option ( what are the variaable..for checkbox). I mean I nned to choose +-x/ and have to modify
wave0_y2 = wave0_y2 + term1accordingly i,e
wave0_y2 = wave0_y2 - term1etc. Can you help me on that issue ?Joined: 2007-06-29
Location: United States
wave0_y2 = wave0_y2 + term1accordingly i,e
wave0_y2 = wave0_y2 - term1etc. Can you help me on that issue ?You don't need a checkbox action procedure. You just need to use ControlInfo to read the state of the checkbox, then make decisions based on that.
There is no simple way to substitute the right operation into your expression at run-time. You must have a series of if statements to choose the right expression. Something like this:
John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
Joined: 2011-08-10
Location: United States
Thank you so much.. now I has a new problem ...
controls Check1, Check2 etc are not defined inside Function copy22(AorB). How to access those control values inside the Function ?
Joined: 2007-06-21
Location: United States
Use the ControlInfo operation.
Joined: 2011-03-14
Location: United States
Controls don't have to be defined in other functions. Since they exist as part of the panel, ControlInfo can return the information for any control within a panel. For checkboxes, the value will be returned in V_Value (a default variable used by ControlInfo so you don't have to declare this one either). The output for various controls is explained in the Manual.
Joined: 2011-08-10
Location: United States
Hi
I really need little bit more help...I didnt find any example of controlinfo specially how to use it in loops...if I declare something like
it does not give any error ..but I cant use such condition inside the loop i,e
...as always it gives error..
Can you pl help ?
Joined: 2007-06-21
Location: United States
To find examples, choose Help->Search Igor Files to search procedure files in the Igor Pro Folder.
To learn about Search Igor Files, execute this:
You will want to search procedure files in the Igor Pro folder for ControlInfo.
Joined: 2011-08-10
Location: United States
Thanks a lot...Its working now with ControlInfo...thnaks to all of you ....Only I have two small problem...
a) How can I make checkbox tick option to be selected one at a time...means if the user choose * then all other checkbox will not have tick, currntly one can tick in all the boxes.
b) How can I make a random name or better a seqeuntial name for a new wave i,e in "Duplicate/O y2, wave0_y2" how can I make new wave ( wave0_y2) name something combining old wave "y2" and a random number or better a sequence of number like y2_a, y2_b etc.
Joined: 2007-06-21
Location: United States
Your control action procedure needs to uncheck all of the other checkboxes when one of them is checked by the user.
If you implement this behavior (only one checked at a time) I recommend that you give your checkboxes "radio button" appearance. See the Checkbox operation mode keyword.
Try the UniqueName function.