Store plot values in a variable and then plot it

8 ビュー (過去 30 日間)
Julen Vicente Pipaon
Julen Vicente Pipaon 2022 年 3 月 17 日
回答済み: Simon Chan 2022 年 3 月 17 日
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)

採用された回答

Simon Chan
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 件)

カテゴリ

Help Center および File ExchangeInterpolation についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by