&& operators issue in MATLAB -


here code:

friendly_output = num2str(std(counts_channel),'%.4f'); if friendly_output > 0 && friendly_output <= 1000     variable = 100 elseif friendly_output > 1000 && friendly_output <= 1500     variable = 500 

the variable friendly_output here decimal number. however, while executing code, prompts me error:

operands || , && operators must convertible logical scalar values

i tried solve issue replacing && &, program works, variable friendly_output failed catch correct if statement.

i tried output value of friendly_output, value correct statement goes wrong.

thank you.

if guess correct, friendly_output of type char

to check that, try this:

class(friendly_output) 

if need compare integer, need convert number.

to add code after first line

friendly_output = str2double(friendly_output); %// changed `eval` `str2double` suggested @horchler %// using `str2double` on `eval` or `str2num` best practice. %// or avoid `num2str` conversion 

ps:

the && operator didn't work because work on scalar inputs. friendly_output variable char array, got error.

while & works on array inputs, each char first converted corresponding ascii value , compared number. though matlab doesn't post error, results won't favorable you.

for more information on difference between & , && refer here

here example of happening when don't convert string number:

>> = '1200.5'  =  1200.5  >> > 1000  ans =   0     0     0     0     0     0 

the ascii values of char 0-9 ranges 49-57 while ascii value of char '.' 46

although, 1200.5 greater 1000, calculate way

50(char '1') not greater 1000.
51(char '2') not greater 1000.
49(char '0') not greater 1000.
49(char '0') not greater 1000.
46(char '.') not greater 1000.
54(char '5') not greater 1000.


Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -