How to save x, y plot data in one variable

38 Ansichten (letzte 30 Tage)
joynjo
joynjo am 17 Jul. 2018
Bearbeitet: Jitender Gangwar am 27 Jul. 2018
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
  2 Kommentare
KSSV
KSSV am 17 Jul. 2018
You should look in for logical indexing.
joynjo
joynjo am 18 Jul. 2018
could you give example or reference?

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Jitender Gangwar
Jitender Gangwar am 27 Jul. 2018
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 Kommentare
Adam
Adam am 27 Jul. 2018
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 am 27 Jul. 2018
Bearbeitet: Jitender Gangwar am 27 Jul. 2018
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.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Graphics Object Programming finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by