Plotting multiple vectors from a function
10 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
RACHNA DANDWANI
el 6 de Jun. de 2018
Comentada: RACHNA DANDWANI
el 13 de Jun. de 2018
Hello everyone. I have a function which returns 'n' sets of 3 values 'Ax', 'Ay' and 'Az'. I want to plot all the 'n' sets for 'Ax', 'Ay' and 'Az' on the same axis. How can it be done?
3 comentarios
Stephen23
el 6 de Jun. de 2018
"I have a function which returns 'n' sets of 3 values 'Ax', 'Ay' and 'Az'."
This is not clear. Do you have a function with three scalar outputs, and you call this function n times, or do you call the function once and it returns three outputs each with n values, or something else?
" I want to plot all the 'n' sets for 'Ax', 'Ay' and 'Az' on the same axis."
What kind of plot: as a line plot, a scatter plot, a bar plot, ... ? Do the Ax, Ay, and Az indicate dimensions to plot?
Respuesta aceptada
Stephen23
el 12 de Jun. de 2018
Simpler than the accepted answer is to use a loop:
for k = 1:N
[Ax,Ay,Az] = yourFunction(...);
plot3(Ax,Ay,Az)
hold on
end
0 comentarios
Más respuestas (1)
Prajit T R
el 11 de Jun. de 2018
Hi Rachna
As Rik mentioned, you need to use plot3 when you have three variables 'x', 'y' and 'z'. I presume that you have many sets of three values like 'Ax','Ay','Az' as one set, 'Bx','By','Bz' as the second set and so on for 'n' sets.
Let us say the size of each is 1x10. Now you wish to plot each of these 'n' sets with the corresponding 3 values each time in the same plot. You can do that as follows:
plot3(Ax,Ay,Az);
hold on
plot3(Bx,By,Bz);
.
.
.
plot3(Zx,Zy,Zz);
This will give you the plots of all 'n' sets (here, n=26 for example) in the same graph.
Hope this helps.
Prajit
3 comentarios
Stephen23
el 12 de Jun. de 2018
Editada: Stephen23
el 12 de Jun. de 2018
"but what if value of 'n' is very large? I can't go on using hold on so many times."
You are right, that would be a crazy way to write code. But you accepted this answer, which means that you are happy that it does exactly what you want. If you wanted to write simpler code though, you could use a loop, like my answer shows.
" How can I plot graphs such that horizontal axis is the same but vertical axis takes 3 different parameters?"
Standard MATLAB allows two y-axes: one of the left, one on the right. For multiple Y-axes you can find some submissions on MATLAB File Exchange:
Ver también
Categorías
Más información sobre 2-D and 3-D Plots en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!