for loop only shows the value of last iterations
Show older comments
Hi everyone, I'm having a problem while using 'for' loop in my coding. Suppose I will get a set of result in 1x12 matrix with a combination of values and empty variable but the results only shows the value of the last iteration. Is it possible if I can obtain and store every values on P1 with respect to its R value for the equation shown in the last line?
Thank you very much for your help.
Po = 101325;
V = 12000;
E = V .* (3.5.*10.^6);
Z = [25 50 100 200 300 400 600 1000 1500 2500 5000 10000];
R = Z / ((E/Po).^(1/3));
for i = min(R):max(R);
if i <= 0.6;
P1 = 0.01;
elseif R <= 7;
P1 = (-0.0014) .* i + 0.01;
else
P1 = [];
end
end
Ps1 = P1 .* Po;
2 Comments
No, a matrix cannot contain an []. For example,
P1=1:5,
P1(5)=[]
Han Xian Chia
on 1 Jul 2021
Accepted Answer
More Answers (1)
Here is what you could do.
I=min(R):max(R);
G=discretize(I,[-inf,0.6,7,inf], 'IncludedEdge','right');
P1=nan(size(I));
P1(G==1)=0.01;
P1(G==2)=(-0.0014) .*I(G==2)+0.01;
1 Comment
Han Xian Chia
on 1 Jul 2021
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!