How to save x, y plot data in one variable
10 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuestas (1)
Jitender Gangwar
el 27 de Jul. de 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 comentarios
Adam
el 27 de Jul. de 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
el 27 de Jul. de 2018
Editada: Jitender Gangwar
el 27 de Jul. de 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.
Ver también
Categorías
Más información sobre Graphics Object Properties en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!