MATLAB: If statement for a values in a string

if statementstring

Iam a Matlab newbi, so need some help. Working on a for-loop. In the for-loop my if statement doesn't work as i wish. I want it to work like this: When the value of i= one of the numbers in the string, h, make a plot of the function f(i). So the problem is the first line in the if-statement.
h=[8 17 25 30 36 41 49 58]
for i=1:65
F(i)
if i= one of the values in the string defined above
plot F(i)
end
end
Any suggestions to fix this if-statement?

Best Answer

The variable h does appear to be a string, but rather a vector of doubles. What you want to use to determine if a scalar is equal to any element of a vector is the function ismember
Example
ismember(i,h)
Hope this helps.
Related Question