How to plot multiline with variable inputs
5 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I have vibration data from several components, and I'm trying to create a multi line plot that allows the user to select multiple variables versus time. I can easily script a multi line plot, but I want to make the number of dependent variables flexible, rather than static.
Instead of scripting "plot(x, y1, x, y2, ..., x, yn), I'd like to pass a variable as an index that references the table where the x and y values are stored.
For example: plot(x, vars(:,3), x, vars(:,4)..., x, vars(:,n))
{where x = vars(:,1) or vars(:,2), which are independent variables in my data table}
Is it possible to make the plot function dynamically sized based on the user input?
Thanks in advance
3 comentarios
Respuestas (3)
ANKUR KUMAR
el 2 de Feb. de 2018
Up to my understanding of your question, I think you are struggling to plot.
You can try this one. Sorry, if I misunderstood your question.
A={rand(1,10),rand(1,10),rand(1,10),rand(1,10)}
col={'g','k','b','r'}
for ii=1:4
plot((1:10),A{ii},col{ii})
hold on
end
2 comentarios
Stephen23
el 3 de Feb. de 2018
Editada: Stephen23
el 3 de Feb. de 2018
There is no point in making this so complicated: no slow ugly loop or complex code is required. All you need is
plot(x, vars)
because plot will plot the columns of vars against x. You can easily add indexing as required, e.g.:
plot(vars(:,2),vars(:,4:end))
Ver también
Categorías
Más información sobre Creating, Deleting, and Querying Graphics Objects en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!