How to save x, y plot data in one variable

조회 수: 38 (최근 30일)
joynjo
joynjo 2018년 7월 17일
편집: Jitender Gangwar 2018년 7월 27일
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
KSSV
KSSV 2018년 7월 17일
You should look in for logical indexing.
joynjo
joynjo 2018년 7월 18일
could you give example or reference?

댓글을 달려면 로그인하십시오.

답변 (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 Programming에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by