MATLAB: Issue when using ‘for’ and ‘elseif’

countelseifforMATLAB

hi, im very new to matlab and i'm trying to write code which sorts through a table and finds values which adhere to the conditions ie waveheight is 2<x<4 or 4<x<6 etc.
the code is below, my issue is whenever i try write the count-
"for T2 =1:size(T2)"
it just gives me an output of 1, I have worked out the 'elseif' segment of this code but it wont work unless I get this for loop to work. I've tried loads of different variations of code but i just cant seem to get it to work
I am also on mac
thanks, ben.

Best Answer

Ben - from your code,
a=readtable('data-all .xlsx','range','G2:G500');
a.Properties.VariableNames = {'waveheight'};
it looks like you have a single column which you have named waveheight. To get a column of this data, you would then do
waveheightData = a.waveheight;
and iterate over it like
for k = 1:length(waveheightData)
if waveheightData(k) > 2 && waveheightData(k) < 4
% do something

elseif waveheightData(k) > 4 && waveheightData(k) < 6
% do something
%etc.
end
end
So you would set up all the conditions necessary to group the data by intervals. You would probably want to create an array of elements, one for each interval, and then increment that element in the % do something part of the code.