Nesting smaller loops under a bigger loop

sumtable=zeros(4,9);
cutoff=20;
for i=1:nrf
sumtable(1,i)=mean(mean(vdprop(:,:,i)));
end
for i=1:nrf
sumtable(1,i+3)=mean(mean(vdprop(1:cutoff,:,i)));
end
for i=1:nrf
sumtable(1,i+6)=mean(mean(vdprop(cutoff+1:end,:,i)));
end
How can I nest the above three loops into another bigger loop?

Antworten (1)

Ghazwan
Ghazwan am 8 Okt. 2022

0 Stimmen

assuming you have the value of nrf. Another outside loop would be:
sumtable=zeros(4,9);
cutoff=20;
for ii=1:20 %or whatever number you need instead of 20
for i=1:nrf
sumtable(1,i)=mean(mean(vdprop(:,:,i)));
end
for i=1:nrf
sumtable(1,i+3)=mean(mean(vdprop(1:cutoff,:,i)));
end
for i=1:nrf
sumtable(1,i+6)=mean(mean(vdprop(cutoff+1:end,:,i)));
end
end

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Hilfe-Center und File Exchange

Produkte

Version

R2022b

Gefragt:

am 8 Okt. 2022

Beantwortet:

am 8 Okt. 2022

Community Treasure Hunt

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

Start Hunting!

Translated by