Hello,
I am stuck on trying to write what I think should be a simple and easy if-else statement, but I just seem to be having trouble connecting the dots…Lets says I have a column vector,
x = [2300:8:2458]';
and I would like to write an if-statement where each row (or element) in the x-vector will be looked at to see if the value meets these two conditions, for example,
if x >= 1 & x <=2440 "some statement goes here"
if it is true, then I would like to keep those values in the column vector, x, (or maybe create a new vector that contains the values that meet the if-condition). If not, I would like to delete those values from the x-vector, for example something like this,
else x = []; end
My guess is that it has something to do with the if-statement returning a logical value and I'm supposed to somehow write a statement that uses that logical value to help determine what values to store and what values to delete, or something like that…Or do I have to write a for loop outside of the if-statement and run it as many times as the length(x)?? I read somewhere that by using a single &, the if-statement looks at each element in the vector…but I'm not entirely sure. Can anyone please help?? I am using 2015a btw. Thanks!
Best Answer