Run assignment command based on if else in command browser
ankit7540
Hello all,
This is a simple assignment operation to the column of an existing wave 'BA' based on a condition,
if ( BA [p][0] >1e4) ;
BA [][1] = sqrt ( BA [p][0] + 0.08 * BA [p][0] );
else
BA [][1] = sqrt ( BA [p][0] + 0.01 * BA [p][0] ) ;
endif ;
BA [][1] = sqrt ( BA [p][0] + 0.08 * BA [p][0] );
else
BA [][1] = sqrt ( BA [p][0] + 0.01 * BA [p][0] ) ;
endif ;
Above can be very easily executed using a defined function. I wonder if this can be run directly in the command browser.
I tried the linearized version of the above, as a one-liner, in the command browser but I receive error "Expected wavename, variable or operation".
Any suggestions.
BA[][1] = (BA[p][0] > 1e4) ? sqrt(BA[p][0] + 0.08 * BA[p][0]) : sqrt(BA[p][0] + 0.01 * BA[p][0])
I haven't tested this, but this is the format of the type of expression you need.
September 5, 2020 at 07:50 am - Permalink
Thanks. It works as expected.
The format seems :
assignment = (condition) ? yes (do this) : no (do this)
September 5, 2020 at 07:19 pm - Permalink
Yes, you can read more about this under the section for the 'conditional operator' in the following chapter:
DisplayHelpTopic "Operators"
September 5, 2020 at 11:03 pm - Permalink
And if you need to that for strings see SelectString.
September 6, 2020 at 06:42 am - Permalink
Btw. you don't need semicolons at the end of line in Igor.
September 6, 2020 at 10:01 am - Permalink