How do I plot a function with a variable that has multiple values?
4 次查看(过去 30 天)
显示 更早的评论
Hi! I'm new to matlab and i don't know how do i plot a graph that need to have X equal to 0, 0,5 and 1, while my Y is 0,5, and after that i need X to be 0,5 and Y to vary between 0, 0,5 and 1. How do i do that? I want to make 2 graphs, one with X varying and Y constant and the second graph having the second case, all in the same code.
0 个评论
回答(2 个)
DGM
2021-7-10
v = [0 0.5 1];
c = [1 1 1]*0.5;
subplot(2,1,1)
plot(v,c,'x-')
subplot(2,1,2)
plot(c,v,'x-')
0 个评论
Soniya Jain
2021-7-10
编辑:Soniya Jain
2021-7-10
Note that the below code will just plot a graph with the marker we mention and not any line on it.
X = [0, 0.5, 1];
Y = [0.5];
plot(X,Y,"-o")
So in 1st case you have to make Y vector same as length of X vector, which can be done without witing it manually, using the below code:
X = [0, 0.5, 1];
Y = zeros(1,length(X)) + 0.5;
plot(X,Y,"-o")
This will plot a straight line parallel to x-axis at y = 0.5.
Similarly, you can do for 2nd case.
To understand plot function in more detail, you can refer the MATLAB documentation of it. (https://in.mathworks.com/help/matlab/ref/plot.html)
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!