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;

Antworten (1)

DGM
DGM am 12 Aug. 2021
Bearbeitet: DGM am 12 Aug. 2021
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 Kommentare

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');
...

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Creating, Deleting, and Querying Graphics Objects finden Sie in Hilfe-Center und File Exchange

Produkte

Version

R2014a

Gefragt:

am 11 Aug. 2021

Kommentiert:

DGM
am 27 Aug. 2021

Community Treasure Hunt

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

Start Hunting!

Translated by