It's difficult to follow a conversation when some comments have been deleted... I cannot see any table in any of the code that has been posted.
Anyway, one thing for sure,
has never been valid syntax in matlab and will indeed result in the error mentioned in the title of the question. The {} are not valid here. While in maths, you can use {} as brackets similar to (), in matlab it means something completely different. The correct syntax is
Making up your own syntax is not going to be very succesful. You need to read the documentation and use the exact same syntax that is stated. Another made up syntax is
While this will not throw an error, it will certainly not produce the result desired. The above will evaluate first -0.15 < SS which will produce a true (1) result or false (0) result. It will then compare that 0 or 1 with 0.15. The end result is that the expression produces a true result for any SS <= -0.15 and false otherwise. Not what was intended at all!
The correct expression is:
Also note that
if (HP > 0.15)||((HP > -0.15 )&& (SS > 0.05))||((HP > -0.15 )&& (SS < -0.05))
reduces to simply:
Finally, note that the preallocation of E and V should be done outside the loop and since E and V are meant to contain numbers they shouldn't be allocated as logical but as double. So, code with all the mistakes removed:
E = zeros(size(m, 1), 1);
V = zeros(size(m, 1), 1);
for i= 1:size(m, 1)
HP = m(i,1);
SS = m(i,2);
if HP==0 && SS==0
E(i,1) = 1;
V(i,1) = 0.167;
elseif HP > 0.15
E(i,1) = 2;
V(i,1) = 0.167;
elseif HP < -0.15
if SS < -0.15 || SS > -0.15
E(i,1) = 10;
V(i,1) = 0.167;
else
E(i,1) = 1000;
V(i,1) = 0.3;
end
elseif HP > -0.15 && HP < 0.15 && SS > -5 && SS < 5
E(i,1) = 6000;
V(i,1) = 0.3;
else
warning('current values of HP and SS not covered by the tests')
end
end
Note that as with your original code, the cases where
- HP == -0.15 || HP == 0.15
- HP is not between -0.15 and 0.15 and SS is greater than 5 or smaller than -5
are not covered by any of the tests, So E an S will stay 0. At least I'm warning you in these cases.
Unlike your original code, the case where HP is <-0.15 and SS is either -0.15 or 0.15 is covered by my tests. It's considered the same as SS being between -0.15 and 0.15.
Best Answer