How to plot a set of vectors dependent on a variable?
16 views (last 30 days)
Show older comments
Hi everyone, I´m still very new to Matlab (and programming in general) and searches in the internet haven´t been really helpful. I would be really grateful if someone could help me. How can I plot a whole set of vectors, that are dependent on a variable with certain values? For example: F=[x^2, 3x], with x [0, 100] (isn´t the one I need to work at). How could I plot these 100 functions without giving the command plot (x^2, 3x) a hundred times? Also, how would i be able to centre the whole thing around the point of origin, and make it a vector polygon?
I´m really sorry if someone else already posted this - I havn't found anything.
0 Comments
Answers (1)
KL
on 18 Nov 2017
Simply create a vector for x,
x = 1:100;
now calculate your result, say y,
y = [x.^2; 3*x];
in the above line, we are creating a matrix where first row calculates x² (x.^2 meaning, taking square of every element) and second row calculates 3x.
now plot it against x by simply saying,
plot(x,y)
now you can also add legends to identify two curves by,
legends('x^2','3*x')
4 Comments
Steven Lord
on 18 Nov 2017
Based on your description the compass or quiver functions may be a better fit for your application than plot.
See Also
Categories
Find more on Line Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!