Store plot values in a variable and then plot it
8 次查看(过去 30 天)
显示 更早的评论
I am trying to save the values of the first figure in a variable and then plot it.
But as you can see my code doesn't plot the same thing in the first figure and in the second one.
I don't know if plotdata.XData(index) and plotdata.YData is what doesn't work or if it is the greiddedInterpolant.
M=200; %Slope of my lines
x=linspace(0,M,127);
y=linspace(0,1,127);
x1=linspace(M,255,127);
y1=linspace(1,0,127);
hold on
plotdata=plot(x,y)
plotdata1=plot(x1,y1);
hold off
[~, index] = sort(plotdata.XData);
F = griddedInterpolant(plotdata.XData(index), plotdata.YData(index));
[~, index] = sort(plotdata1.XData);
F1 = griddedInterpolant(plotdata1.XData(index), plotdata1.YData(index));
F2=[F.Values F1.Values];
figure
plot(F2)
0 个评论
采纳的回答
Simon Chan
2022-3-17
F.Values and F1.Values are those y-values only and hence the plot does not have any information about the corresponding x-values.
The x-value are stored in F.GridVectors and F1.GridVectors so modifying the last line is able to plot the 2nd figure correctly,
M=200; %Slope of my lines
x=linspace(0,M,127);
y=linspace(0,1,127);
x1=linspace(M,255,127);
y1=linspace(1,0,127);
plotdata=plot(x,y);
hold on
plotdata1=plot(x1,y1);
hold off
[~, index] = sort(plotdata.XData);
F = griddedInterpolant(plotdata.XData(index), plotdata.YData(index));
[~, index] = sort(plotdata1.XData);
F1 = griddedInterpolant(plotdata1.XData(index), plotdata1.YData(index));
figure
plot([F.GridVectors{1},F1.GridVectors{1}], [F.Values, F1.Values]);
0 个评论
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

