How to write a loop that does not increase by +1?
显示 更早的评论
Hello :) I currently need to run a loop with the output of "find(collated(1,:) ==0 )". Currently, the output is [2 ; 4 ; 5 ; 6 ; 8], and I need to run the loop with these indexes. I couldn't use a for loop as the number are not increasing by 1. Is there a way I could manage the loop so that the output does not have to run in an +1 order? I read that a while loop may be useful, but am still new to the while loop.
PS
the matrix 'collated' is a 35 x 9 logical, so the idea that I want the code to work is that with each row of collated, I find the 0s i.e in row 1, it will be [2 ; 4 ; 5 ; 6 ; 8], row 2 [2 ;3], row 3 [4; 7; 8; 9] etc...
Appreciate any sort of help! :)
for k = 1:35
while A == find(collated(k,:) ==0)
selectedlocal = find(sesslocal == A);
pfc = dataset_p(1,:);
fef = dataset_f(1,:);
zpfc = zscore(pfc);
zfef = zscore(fef);
zzpfc = zpfc(selectedlocal);
zzfef = zfef(selectedlocal);
[R,P] = corrcoef(zzpfc,zzfef)
end
end
3 个评论
madhan ravi
2020-2-22
You haven’t shared the missing datas and your expected result. This would delay the possibility of giving a perfect answer.
David Goodmanson
2020-2-22
Hi charms, you can do
for k = 2:2:8
(do stuff that depends on k)
end
since the middle 2 sets the increment value
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Numerical Integration and Differentiation 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!