Passing variables to plot function
Mostrar comentarios más antiguos
I have the following plot function
plot([2,7],[3,3],'lineWidth', 40);
Instead of [2,7], I want to pass two variables d1 and d2 that has a set of values stored in it. Can someone please help me with that?
Respuestas (2)
dpb
el 13 de Abr. de 2016
Well, it would seem pretty straightforward,
plot(d1,d2,'lineWidth', 40);
assuming X, Y values are in d1, d2, respectively, and they're the same length vectors.
See
doc plot % for details on using it
2 comentarios
Hari
el 13 de Abr. de 2016
dpb
el 13 de Abr. de 2016
I'm sure I don't understand from the description. What are the sizes of the various variables and what do you actually want plotted?
The general answer is that plot expects an X and Y array of commensurate length; if vectors orientation doesn't matter. You can do whatever manipulations you need with the variables to build the desired X and Y, plot doesn't care how you write the arrays as long as it is valid syntax that could be written to store the result as a variable.
Muhammad Usman Saleem
el 13 de Abr. de 2016
Editada: Muhammad Usman Saleem
el 13 de Abr. de 2016
let see it what you want
>> d1=[1 3 5 6] % create a vector as x for plot
d1 =
1 3 5 6
>> d2=[4 5 0 10] % create a vector as y for plot
d2 =
4 5 0 10
>> plot(d1,d2,'lineWidth', 40);
do not use [] in d1 and d2
here is the output plot,

5 comentarios
Hari
el 13 de Abr. de 2016
dpb
el 14 de Abr. de 2016
Not much interesting in a plot in which all the y values are the same; it'll just be a horizontal line; the locations of x will be immaterial.
But, the size of the two vectors X and Y must be the same as above so you'd need
plot([d1 d2],3*ones(1,length(d1)+length(d2)),'linewidth',40)
to draw the line with those points.
Muhammad Usman Saleem
el 14 de Abr. de 2016
In order to store multiple value of d1, d2 you can use for loop.
Define before some vectors (either one of them is remain unchanged) and then in plot function use them as input x,y.
I think you want to plot multiple plots of different vector? Will you please tell me what are your d1,d2? I shall give you quick approch
Muhammad Usman Saleem
el 15 de Abr. de 2016
good then please accept answer for reputation.
Categorías
Más información sobre Graphics Performance en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!