How to plot a set of vectors dependent on a variable?
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.
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
Sean Zettl
on 18 Nov 2017
KL
on 18 Nov 2017
Is there a way of getting the different vectors from the origin to the different points?
well, without knowing what are the values of those vectors or what are the different points, it's hard to help you further. Instead of x being a vector (from 0 to 100), if you want to perform the same operation for various values, create a matrix!
x = [0:100;
some_value:some_other_value;
%and so on];
if you want to generate random numbers use
x = rand(numberofrows,numberofcolumns)
the way you calculate y and plotting after that should remain like the above simple example.
Provide more information, if you need further help.
Sean Zettl
on 18 Nov 2017
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.
Categories
Find more on Vector Fields 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!