How to fix the "Improper index matrix reference" error in my Data Extraction coding?

I am trying to extract data from the MATLAB figure 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" this message. So, how do I resolve the error and extract data from the figure?
//
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 件)

dpb
dpb 2021 年 8 月 1 日
編集済み: dpb 2021 年 8 月 2 日
hF=openfig('NF power_Aulayers_etch_glass-by-glass_xz.fig');
hAx=hF.Children; % the axes object handle
hS=hAx.Children; % the children of the axes 2-array
hS=hS{2}; % the surface handle is second of the two
X=hS.XData;
etc., ...
Given the roundabout of the above, I'd suggest the more direct
>> hS=findobj(hF,'type','surface')
hS =
Surface with properties:
EdgeColor: 'none'
LineStyle: '-'
FaceColor: 'flat'
FaceLighting: 'flat'
FaceAlpha: 1
XData: [251×1 double]
YData: [81×1 double]
ZData: [81×251 double]
CData: [81×251 double]
Show all properties
>>
or your original will result in same thing--
>> hS=findobj(hF,'-property','XData')
hS =
Surface with properties:
EdgeColor: 'none'
LineStyle: '-'
FaceColor: 'flat'
FaceLighting: 'flat'
FaceAlpha: 1
XData: [251×1 double]
YData: [81×1 double]
ZData: [81×251 double]
CData: [81×251 double]
Show all properties
>>

6 件のコメント

M M Shaky
M M Shaky 2021 年 8 月 1 日
Thank you for your reply.
However, it's showing "Attempt to reference field of non-structure array." error, once I am running it.
Can you provide an alternative solution?
dpb
dpb 2021 年 8 月 1 日
Oh, sorry...I left out an intermediary...the surface is a child object of the axes...
Edit above.
M M Shaky
M M Shaky 2021 年 8 月 2 日
Thank you again.
But, the first one is still showing the same "Attempt to reference field of non-structure array." error.
and the second one is responding with a prompt message "The selected section cannot be evaluated because it contains an invalid statement".
dpb
dpb 2021 年 8 月 2 日
Oh. I see the first actually returns a 2x1 cell array; there's an empty GraphicsPlaceholder returned besides the Surface object. I didn't realize that; sorry. So, the first needs must dereference the second cell with
hS=hS{2};
Owing to that I'd opt for the second to retrieve the Surface object handle directly.
It (the latter) works as advertised--
>> hF=openfig('NF power_Aulayers_etch_glass-by-glass_xz.fig');
>> hS=findobj(hF,'type','surface')
hS =
Surface with properties:
EdgeColor: 'none'
LineStyle: '-'
FaceColor: 'flat'
FaceLighting: 'flat'
FaceAlpha: 1
XData: [251×1 double]
YData: [81×1 double]
ZData: [81×251 double]
CData: [81×251 double]
Show all properties
>> X=hS.XData; Y=hS.YData; Z=hS.ZData;
>> whos X Y Z
Name Size Bytes Class Attributes
X 251x1 2008 double
Y 81x1 648 double
Z 81x251 162648 double
>>
So on that one would have to see your session code in context to be able to spot any differences.
M M Shaky
M M Shaky 2021 年 8 月 9 日
編集済み: M M Shaky 2021 年 8 月 9 日
Thank you again.
But, It shows "Expression or statement is incomplete or incorrect." error now.
hF=openfig('NF power_Aulayers_etch_glass-by-glass_xz.fig');
hS=findobj(hF,'type','surface');
hS =
Surface with properties:
EdgeColor: 'none';
LineStyle: '-';
FaceColor: 'flat';
FaceLighting: 'flat';
FaceAlpha: 1;
XData: [251×1 double]
YData: [81×1 double]
ZData: [81×251 double]
CData: [81×251 double]
Show all properties
X=hS.XData; Y=hS.YData; Z=hS.ZData;
whos X Y Z
Name Size Bytes Class Attributes
X 251x1 2008 double
Y 81x1 648 double
Z 81x251 162648 double
Fangjun Jiang
Fangjun Jiang 2021 年 8 月 11 日
編集済み: Fangjun Jiang 2021 年 8 月 11 日
Where is the error message? Can you show the commands and error message when it happened?
The fact that X, Y and Z data show up means your quoted code has been executed successfully.

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeGraphics Performance についてさらに検索

製品

リリース

R2014a

質問済み:

2021 年 8 月 1 日

編集済み:

2021 年 8 月 11 日

Community Treasure Hunt

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

Start Hunting!

Translated by