How to save x, y plot data in one variable

17 visualizzazioni (ultimi 30 giorni)
joynjo
joynjo il 17 Lug 2018
Modificato: Jitender Gangwar il 27 Lug 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 Commenti
KSSV
KSSV il 17 Lug 2018
You should look in for logical indexing.
joynjo
joynjo il 18 Lug 2018
could you give example or reference?

Accedi per commentare.

Risposte (1)

Jitender Gangwar
Jitender Gangwar il 27 Lug 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 Commenti
Adam
Adam il 27 Lug 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 il 27 Lug 2018
Modificato: Jitender Gangwar il 27 Lug 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.

Accedi per commentare.

Categorie

Scopri di più su Graphics Object Properties in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by