Store plot values in a variable and then plot it
8 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Julen Vicente Pipaon
le 17 Mar 2022
Réponse apportée : Simon Chan
le 17 Mar 2022
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 commentaires
Réponse acceptée
Simon Chan
le 17 Mar 2022
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 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Interpolation dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

