how make a plot where both x and y are varying?
16 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
bella bridges
el 16 de Feb. de 2023
Comentada: Voss
el 17 de Feb. de 2023
Lets say I have an equation, A=B*C*D
I want to vary C from 1 to 10 with at least 5 values, and get the corresponding A value.
I then want to make a plot of these values with A being the Y-axis, and C being the x-axis.
I also want to make another plot that is the same with A on the Y-axis and C on the X-axis, but in this case B is also changing, along with C.
How would I go about doing this?
I know this is a very basic question, but since I am new to matlab I'm having trouble using the correct search terms or phrasing to find answers already out there.
thank you for any advice.
0 comentarios
Respuesta aceptada
Voss
el 16 de Feb. de 2023
Like this?
C = 1:10; % C changing
B = 1; % B constant
D = 1;
A = B.*C.*D;
subplot(2,1,1)
plot(C,A)
xlabel('C')
ylabel('A')
title('Constant B')
B = 2:11; % B changing
A = B.*C.*D;
subplot(2,1,2)
plot(C,A)
xlabel('C')
ylabel('A')
title('Changing B')
2 comentarios
Más respuestas (1)
Matt J
el 16 de Feb. de 2023
Editada: Matt J
el 16 de Feb. de 2023
For example,
C=(1:10)';
B=linspace(1,4,5);
D=1;
A=B.*C.*D
plot(C,A); legend("B="+B)
3 comentarios
Matt J
el 16 de Feb. de 2023
It's not much different.
C=(1:10)';
B=linspace(1,4,5);
D=1;
A=B.*C.*D;
tiledlayout(2,3);
for i=1:size(A,2)
nexttile
plot(C,A(:,i)); title("B="+B(i))
ylim([0,40])
end
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!