How to create an if loop with conditions

Hi,
in my Time analysis i need to divide my vector 'pupil diameter' in 3 moments and for each one i have to calculate the median
and i did it in this way
%% TIME SPAN ANALYSIS
time_1 = median(diametre(1:33000));
time_2 = median(diametre(33001:66000));
time_3 = median(diametre(66001:99000));
but not all my subject have vector length which reaches 99000 timestamps so i created a loop where i wrote:
for i=1:length(list)
time_1 = median(diametre(1:33000));
time_2 = median(diametre(33001:66000));
if diametre > 66000
time_3 = median(diametre(66001:99000));
end
list is the list of my participant. When it comes to calculate time_3 then it tell me that the matrix exceed the dimension so it means that the loop doesnt work despite i check the length of the signal in all my participant before choosing where to cut
can you please help me write it correctly?
thank you very much in advance

 Réponse acceptée

Walter Roberson
Walter Roberson le 28 Août 2022
if numel(diametre) > 66000

5 commentaires

GB92_R
GB92_R le 28 Août 2022
Hi,
thank you for your answer but it still tells me that the matrix exceed the dimension
if numel(diametre) >= 99000
GB92_R
GB92_R le 28 Août 2022
it doesn't work either.
it stops at the first participant with a diameter length of 80000
and the error says
Undefined function or variable 'time_1'.
for i=1:length(list)
What is list ?
time_1 = median(diametre(1:33000));
You do not appear to be using the value of i so it is not clear why you are looping there.
If list were empty, then after the for loop, time_1 would be undefined.
Be careful, when diametre is small, time_3 would be undefined.
GB92_R
GB92_R le 28 Août 2022
yes, thank you
it works !

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Loops and Conditional Statements dans Centre d'aide et File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by