for loop with 3 variables
Show older comments
xvirtual = [250:10:300]
for jj = 1:length(xvirtual)
for j = 50000:50100 %:length(Z(:,1))
for i = xvirtual(jj):length(xq(1,:))-1
V(j,i) = pointdistance*(Z(j,i)-Zq(i));
end
Volume(j) = sum(V(j,:) ,'omitnan'); % virtual overtopping volumes in time
end
Vis(jj,:) = Volume;
end
Hi hope someone can help me with this code. I want to loop through time=j, the space =i and different xvirtual levels = jj. As result I get Vis, however this result contains the same volumes for all rows. So probably it is only calculating for the first xvirtual=250. How can I calculate for the other values of xvirtual?
4 Comments
Adam
on 4 Feb 2019
Why are you indexing j from 50000? This will create V and Volume variables vastly bigger than required, with 0s form the previous 49999 elements/rows.
ceycey
on 4 Feb 2019
Cris LaPierre
on 4 Feb 2019
Edited: Cris LaPierre
on 4 Feb 2019
Hard to say without knowing more about the other variable: pointdistance, Z, Zq and xq. Can you attach a mat file containing them? Or at least provide info on their size?
ceycey
on 5 Feb 2019
Accepted Answer
More Answers (0)
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!