Removing number from for loop

Viewed 56

I have a question about Matlab.

My chunk of code looks like this:

piece = 1:25;
piece([12]) = [];

for sub = 1:(valid_subject)
    group_data = [];
    for j = 1:length(piece)
        group_data = [group_data; subject_data{sub}.trial{j}'];
    end
    group_mat(:,:,1,sub) = group_data
end

What I want to do is to loop through all trials, from 1 to 25, but omitting trial 12. By using length(piece) I just go through 24 numbers, from 1 to 24. Do you know another way to have numbers from 1 to 25 without 12 as j?

Thank you!

1 Answers

You have modified piece removing 1 item therefore piece now only has 24 elements and you are telling the for loop to follow [1:1:length(piece)]

Instead of for j=1:length(piece) use for j=1:piece

Related