Re: "Expression Must be a Scalar in this context:" error in nlinlsq function [message #81221] |
Tue, 28 August 2012 23:23 |
Yngvar Larsen
Messages: 134 Registered: January 2010
|
Senior Member |
|
|
On Tuesday, 28 August 2012 18:27:51 UTC+2, elambrid wrote:
>> I would say that the variable aoffxc is a five-element byte array,
>
>>
>
>> when it should be a one-element scalar to use it in a boolean
>
>>
>
>> expression like this. :-)
>
>
>
>> David
>
>
>
> Yes I agree, so I guess what I'm confused about is nlinlsq works like a for loop where the iterations are determined by the amounts of "functions", better word would be the size of you data set. So I have all these variables that look like this e.g a=[b(0)...b(n)] How would I check if one of those values are zero, and perform a statement on them? And thank you for your speedy reply!
B = lonarr(42)
w = dblarr(42)
; ...
zero_ind = where(B eq 0, count)
if count gt 0 then w[zero_ind] = 0
Or simply this if you are going to do something if at least one element in B is zero:
if total(B eq 0) gt 0 then dostuff, B
--
Yngvar
|
|
|
Re: "Expression Must be a Scalar in this context:" error in nlinlsq function [message #81233 is a reply to message #81221] |
Tue, 28 August 2012 09:37  |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
elambrid writes:
> Yes I agree, so I guess what I'm confused about is nlinlsq works like a for loop where the iterations are determined by the amounts of "functions", better word would be the size of you data set. So I have all these variables that look like this e.g a=[b(0)...b(n)] How would I check if one of those values are zero, and perform a statement on them? And thank you for your speedy reply!
If you want to check an individual element, you
have to check an individual element!
variable = [0, 1, 1, 0, 4]
FOR j=0,N_Elements(variable)-1 DO BEGIN
IF variable[j] EQ 0 THEN Print, 'variable ' + StrTrim(j,2) + $
' is equal to zero' ELSE Print, 'Good value'
ENDFOR
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
|
|
|
Re: "Expression Must be a Scalar in this context:" error in nlinlsq function [message #81234 is a reply to message #81233] |
Tue, 28 August 2012 09:27  |
Erini Lambrides
Messages: 6 Registered: March 2012
|
Junior Member |
|
|
> I would say that the variable aoffxc is a five-element byte array,
>
> when it should be a one-element scalar to use it in a boolean
>
> expression like this. :-)
> David
Yes I agree, so I guess what I'm confused about is nlinlsq works like a for loop where the iterations are determined by the amounts of "functions", better word would be the size of you data set. So I have all these variables that look like this e.g a=[b(0)...b(n)] How would I check if one of those values are zero, and perform a statement on them? And thank you for your speedy reply!
-Erini
|
|
|
Re: "Expression Must be a Scalar in this context:" error in nlinlsq function [message #81235 is a reply to message #81234] |
Tue, 28 August 2012 09:23  |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
elambrid writes:
> So within the function I am using in nlinlsq, I have a common block that contains some global variables that are found within my main routine and used in my function (for simplicities sake it's called ddr). Since nlinlsq works on a "number of functions" basis you pretty much have to recast everything as 1D. I would like to check within my function if a value of one of my arrays is 0, yet the if statement keeps giving me an error of " Expression must be a scalar in
this context: <BYTE Array(5)>." Below is a sketch of the code. Thanks in advance!
>
> pro auto_target_offset
>
> common offset_vals3,blah1,blah2,blah3,...,blah13,aoffxc,aoffyc
> ...
> solution=nlinlsq("ddr",5,3)
> ...
> end
>
> function ddr,m,r
>
> common offset_vals3 (same as above)
> ...
> if aoffxc eq 0 then w=0
> ...
> end
>
> Thanks again!
I would say that the variable aoffxc is a five-element byte array,
when it should be a one-element scalar to use it in a boolean
expression like this. :-)
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
|
|
|