If my guess is correct, your friendly_output
is of type char
To check that, try this:
class(friendly_output)
If you need to compare it with an integer, you need to convert it back to a number.
To do this add this code after the first line
friendly_output = str2double(friendly_output);
%// changed from `eval` to `str2double` as suggested by @horchler
%// Using `str2double` over `eval` or `str2num` is a best practice.
%// or you could just avoid `num2str` conversion
PS:
The &&
operator didn't work for you because they work good only on scalar inputs. But as the friendly_output
variable is a char
array, you got the error.
While &
works on array inputs, Each char is first converted to its corresponding ASCII value and then compared with the number. So even though Matlab doesn't post an error, the results won't be favorable to you.
For more information on the difference between &
and &&
Refer Here
Here is an example of what is happening when you don't convert the string back to number:
>> a = '1200.5'
a =
1200.5
>> a > 1000
ans =
0 0 0 0 0 0
The ASCII values of char 0-9
ranges from 49-57
while ASCII value of char '.'
is 46
Although, 1200.5 is greater than 1000, it actually calculate this way
50(char '1') is not greater than 1000.
51(char '2') is not greater than 1000.
49(char '0') is not greater than 1000.
49(char '0') is not greater than 1000.
46(char '.') is not greater than 1000.
54(char '5') is not greater than 1000.