how make a plot where both x and y are varying?

16 visualizaciones (últimos 30 días)
bella bridges
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.

Respuesta aceptada

Voss
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
bella bridges
bella bridges el 17 de Feb. de 2023
Yes, I think thats exactly what I'm looking for. Much more simple that I thought for some reason, thank you!
Voss
Voss el 17 de Feb. de 2023
You're welcome!

Iniciar sesión para comentar.

Más respuestas (1)

Matt J
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
A = 10×5
1.0000 1.7500 2.5000 3.2500 4.0000 2.0000 3.5000 5.0000 6.5000 8.0000 3.0000 5.2500 7.5000 9.7500 12.0000 4.0000 7.0000 10.0000 13.0000 16.0000 5.0000 8.7500 12.5000 16.2500 20.0000 6.0000 10.5000 15.0000 19.5000 24.0000 7.0000 12.2500 17.5000 22.7500 28.0000 8.0000 14.0000 20.0000 26.0000 32.0000 9.0000 15.7500 22.5000 29.2500 36.0000 10.0000 17.5000 25.0000 32.5000 40.0000
plot(C,A); legend("B="+B)
  3 comentarios
Matt J
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
bella bridges
bella bridges el 17 de Feb. de 2023
A bit different than what I had in mind, but both of these answers were still useful. thanks!!

Iniciar sesión para comentar.

Categorías

Más información sobre MATLAB en Help Center y File Exchange.

Productos


Versión

R2020a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by