Plotting Problem with multiple numbers under one variable.
16 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I am trying to plot each of the chains below. As you can see, if you run the code, the plot is only plotting the data point for the last i term. How do I plot (i,F_a1) for each i term and not just the last term?
%chain 1
for i=0:0.1:1
f_a=i;
f_b=-i+1;
r_a1=1;
r_b1=1;
F_a1=(((r_a1.*((f_a).^2))+(f_a.*f_b))/((r_a1.*((f_a).^2))+(2.*f_a.*f_b)+(r_b1.*((f_b).^2))));
end
%chain 2
for i=0:0.1:1
f_a=i;
f_b=-i+1;
r_a2=0.25;
r_b2=0.25;
F_a2=(((r_a2*((f_a).^2))+(f_a*f_b))/((r_a2*((f_a).^2))+(2*f_a*f_b)+(r_b2*((f_b).^2))));
end
%chain 3
for i=0:0.1:1
f_a=i;
f_b=-i+1;
r_a3=4;
r_b3=4;
F_a3=(((r_a3*((f_a).^2))+(f_a*f_b))/((r_a3*((f_a).^2))+(2*f_a*f_b)+(r_b3*((f_b).^2))));
end
%chain 4
for i=0:0.1:1
f_a=i;
f_b=-i+1;
r_a4=0.25;
r_b4=4;
F_a4=(((r_a4*((f_a).^2))+(f_a*f_b))/((r_a4*((f_a).^2))+(2*f_a*f_b)+(r_b4*((f_b).^2))));
end
hold on
scatter(i,F_a1,"black","filled")
scatter(i,F_a2,"red","filled")
scatter(i,F_a3,"blue","filled")
scatter(i,F_a4,"green","filled")
title('F_A End Chain Versus f_a Monomer Available')
ylabel('F_A')
xlabel('Amount of f_a Monomer')
legend("Chain 1","Chain 2","Chain 3","Chain 4")
hold off
0 commentaires
Réponses (1)
Star Strider
le 2 Avr 2021
Index them!
Since all the ‘i’ vectors are the same, a few minor corrections (and some repetitive editing) produces:
iv=0:0.1:1;
%chain 1
for k = 1:numel(iv)
i = iv(k);
f_a=i;
f_b=-i+1;
r_a1=1;
r_b1=1;
F_a1(k)=(((r_a1.*((f_a).^2))+(f_a.*f_b))/((r_a1.*((f_a).^2))+(2.*f_a.*f_b)+(r_b1.*((f_b).^2))));
end
%chain 2
for k = 1:numel(iv)
i = iv(k);
f_a=i;
f_b=-i+1;
r_a2=0.25;
r_b2=0.25;
F_a2(k)=(((r_a2*((f_a).^2))+(f_a*f_b))/((r_a2*((f_a).^2))+(2*f_a*f_b)+(r_b2*((f_b).^2))));
end
%chain 3
for k = 1:numel(iv)
i = iv(k);
f_a=i;
f_b=-i+1;
r_a3=4;
r_b3=4;
F_a3(k)=(((r_a3*((f_a).^2))+(f_a*f_b))/((r_a3*((f_a).^2))+(2*f_a*f_b)+(r_b3*((f_b).^2))));
end
%chain 4
for k = 1:numel(iv)
i = iv(k);
f_a=i;
f_b=-i+1;
r_a4=0.25;
r_b4=4;
F_a4(k)=(((r_a4*((f_a).^2))+(f_a*f_b))/((r_a4*((f_a).^2))+(2*f_a*f_b)+(r_b4*((f_b).^2))));
end
figure
hold on
scatter(iv,F_a1,"black","filled")
scatter(iv,F_a2,"red","filled")
scatter(iv,F_a3,"blue","filled")
scatter(iv,F_a4,"green","filled")
title('F_A End Chain Versus f_a Monomer Available')
ylabel('F_A')
xlabel('Amount of f_a Monomer')
legend("Chain 1","Chain 2","Chain 3","Chain 4", 'Location','best')
hold off
That should do what you want.
0 commentaires
Voir également
Catégories
En savoir plus sur Develop Apps Using App Designer dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!