plotting 2 different graphs

1 visualización (últimos 30 días)
Karelle Ngwen
Karelle Ngwen el 30 de En. de 2023
Comentada: Karelle Ngwen el 12 de Feb. de 2023
i have 2 matrices and want to plot each individual value on a separate graph. like the first value of the first matrix and that of the second matrix only on one graph, then the second values of both on another graph
  2 comentarios
Rik
Rik el 30 de En. de 2023
Have a read here and here. It will greatly improve your chances of getting an answer.
Please post some example data, along with what you tried. I suspect a call to subplot, simple indexing, and two calls to plot will suffice.

Iniciar sesión para comentar.

Respuestas (1)

Vinayak Choyyan
Vinayak Choyyan el 8 de Feb. de 2023
Hello Karelle,
As per my understanding, you have two matrices, say A and B, of the same size. You would like to plot just one (X,Y) pair on a graph for each pair (A(i), B(i)), where i is the index of element in matrix.
From your question, I am not sure whether you would like to have just one figure with multiple subplots for each value pair or have multiple figures with plots for each value pair. Hence I am providing you with a solution for both these mentioned cases.
  • One figure with multiple subplots, one subplot for each value pair
a=[1,2,3,4,5;6,7,8,9,10];
b=[2,4,6,8,10;12,14,16,18,20];
%a and b are 2 matrix of same size
sa=size(a);%get the size of a (which is same as b)
for i=1:sa(1)
for j=1:sa(2)
pos=sa(2)*(i-1)+j;%position of current plot in subplot
subplot(sa(1),sa(2),pos);%select the position of subplot among all the subplots
plot(a(i,j),b(i,j),'*');
end
end
  • Many figures, one figure for each value pair
a=[1,2,3,4,5;6,7,8,9,10];
b=[2,4,6,8,10;12,14,16,18,20];
%a and b are 2 matrix of same size
sa=size(a);%get the size of a (which is same as b)
for i=1:sa(1)
for j=1:sa(2)
figure;
plot(a(i,j),b(i,j),'*');
end
end
I hope this helps resolve the issue you were facing.
Please refer to the following documentation to read more about 'plot()' and 'subplot()' functions:
  1 comentario
Karelle Ngwen
Karelle Ngwen el 12 de Feb. de 2023
Thank you this was very helpful

Iniciar sesión para comentar.

Categorías

Más información sobre 2-D and 3-D Plots en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by