How to save x, y plot data in one variable

17 次查看(过去 30 天)
I have x and y variable, then I plot it plot(x,y,'.'). I also have two functions (red line and black line). I need to save the x,y plot data into one variable for further processing i.e. show the data bigger or less the function only. Is there anyone can help, I'll very appreciate

回答(1 个)

Jitender Gangwar
Jitender Gangwar 2018-7-27
You can store the plot data as illustrated below
>> x = [1 2 3];
>> y = [4 5 6];
>> plotData = plot(x,y);
>> plotData
plotData =
Line with properties:
Color: [0 0.4470 0.7410]
LineStyle: '-'
LineWidth: 0.5000
Marker: 'none'
MarkerSize: 6
MarkerFaceColor: 'none'
XData: [1 2 3]
YData: [4 5 6]
ZData: [1×0 double]
Show all properties
Now the variable "plotData" has an object with properties of the figure which contains the plot. You can now access the properties by using "." operator.
>> plotData.XData
ans =
1 2 3
>> plotData.XData(2) = 4;
>> plotData.XData
ans =
1 4 3
Hope this answers your concern and helps you.
  2 个评论
Adam
Adam 2018-7-27
You will need to make sure you save the data from the plot to somewhere else though before you close the figure, if you want this data to persist beyond the lifetime of the figure, else this object will just become a handle to a deleted object and you will lose your data when you close the graph.
Jitender Gangwar
Jitender Gangwar 2018-7-27
编辑:Jitender Gangwar 2018-7-27
As it is correctly pointed out by @Adam, The data from the handle "plotData" needs to be stored before you destroy(OR close) the figure. This can be achieved as follows:
>> plotData = copy(plotData);
PS: Thank you @Adam for your help.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Graphics Object Properties 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by