Line plot not showing up in for loop iteration
Afficher commentaires plus anciens
I looked everywhere for a solution to my problem, but for some reason I just cannot get this to work. All I want to do, is to make a normal line plot inside my for loop to show how values change with each iteration. I can make a plot with something like this:
plot(i,f,'*')
But I don't just want a scatter plot, I would like for there to be an actual line connecting all the points. I know this question has been asked a ton before, but I couldn't find anything with my problem. I also tried to turn them into an array to plot it, but that made me run into a whole bunch of other issues. The thing is, my code gives me the answers I expect but I'm just totally stumped. I appreciate any help I can get. For reference, the variable i is a user input, that will dictate how many iterations to step through. Also the variables G,
for i = 1:i
syms A B C D %stages
eq1 = (g5 * (45 + D + A))/f == D;
eq2 = (g4*D)/f == C;
eq3 = (g3*C+B)/f == B;
eq4 = (g2 * B)/f == A;
%eq5 = (g1 * A)/f == Cin
sol = solve([eq1, eq2, eq3, eq4], [A, B, C, D]);
Asol = eval(sol.A);
Bsol = eval(sol.B);
Csol = eval(sol.C);
Dsol = eval(sol.D);
b1new = (Csol + Bsol)/Csol;
b2new = (Cout+Dsol + Asol)/Cout;
Branchnew = b1new*b2new;
Branch=Branchnew;
fnew = (G*H*Branchnew)^(1/N);
f = fnew;
Fnew = G*H*Branchnew;%new effort
Dnew = N*Fnew^(1/N) + P;
fprintf('Iteration %d:', i)
f
Branch
% amatrix = [Asol; {amatrix}];
% bmatrix = [bmatrix; {Bsol}];
% cmatrix = [cmatrix; {Csol}];
% dmatrix = [dmatrix; {Dsol}];
% imatrix= [imatrix; i];
hold on
figure(1);
plot(i,f, 'r-o')
figure(2);
plot(i,f)
i=i+1;
end
hold off
Réponse acceptée
Plus de réponses (1)
Jan
le 14 Nov 2021
0 votes
What exactly is trhe problem with your code?
Maybe all you need is to insert a drawnow command after the plotting?
By the way, you do not need the i=i+1 command in Matlab. The for command does increment the counter already. so incrementing it by you own is confusing only.
1 commentaire
Jonathan Gerges
le 14 Nov 2021
Modifié(e) : Jonathan Gerges
le 14 Nov 2021
Catégories
En savoir plus sur Logical dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!



