How to rectify the "Improper index matrix reference" error in my coding for two dimensional data extraction from MATLAB Figure?

I am trying to extract arrays of two dimensional data from the MATLAB figure file named "NF power_Aulayers_etch_glass-by-glass_xz" as attached. But, when I run the code, it doesn't extract the data, rather it shows "Improper index matrix reference" error message. So, how do I resolve the error and extract arrays of two dimensional data from the figure?
Note: I am using MATLAB R2014a.
Kindly help me to use the following code in MATLAB R2014a.
fig = openfig('NF power_Aulayers_etch_glass-by-glass_xz.fig');
Extracted_data = findobj(fig,'-property','XData','-property','YData','-property','Zdata');
x = Extracted_data(1).XData;
y = Extracted_data(1).YData;
z = Extracted_data(1).ZData;

답변 (1개)

DGM
DGM 2021년 8월 12일
편집: DGM 2021년 8월 12일
A lot of graphics stuff changed between R2014a/b. When you run findobj() in the older versions, the result Extracted_data is a handle in the form of a number (literally numeric class). In the later versions, it's a proper graphics object.
In R2009b:
>> class(Extracted_data)
ans =
double
in R2019b:
>> class(Extracted_data)
ans =
'matlab.graphics.chart.primitive.Surface'
Both of these are correct and usable with the conventions of their own era. The obvious thing to note is that you can't use dot indexing on a numeric scalar. Instead, you'd use get()/set() to access the obj it references. Since they're expecting that number to be a handle, they'll know what it means contextually.
x = get(Extracted_data,'XData');
y = get(Extracted_data,'YData');
z = get(Extracted_data,'ZData');
IDK that I explained that exactly right, but it's probably close enough.

댓글 수: 2

Thank you for your help.
But, Can you please write down the complete code in order?
fig = openfig('NF power_Aulayers_etch_glass-by-glass_xz.fig');
Extracted_data = findobj(fig,'-property','XData','-property','YData','-property','Zdata');
x = get(Extracted_data,'XData');
y = get(Extracted_data,'YData');
z = get(Extracted_data,'ZData');
...

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

카테고리

도움말 센터File Exchange에서 Creating, Deleting, and Querying Graphics Objects에 대해 자세히 알아보기

제품

릴리스

R2014a

질문:

2021년 8월 11일

댓글:

DGM
2021년 8월 27일

Community Treasure Hunt

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

Start Hunting!

Translated by