Accessing data in 1x2 structure array

10 ビュー (過去 30 日間)
Tadgh Cullen
Tadgh Cullen 2015 年 6 月 9 日
編集済み: Stephen23 2015 年 6 月 9 日
I'm trying to simply plot the X and the Y data from the data set given to me (see attached image) but I don't seem to be seeing the full data set when I do. For example, I load in the x and y data and plot
x=data.X
y=data.Y
imagesc(x) etc etc etc
Whats confusing me is - the X data is originally in a 1x2 structure so when I load in the data like I did above, what exactly am I loading in? Am I loading in the full 1x2 structure or only the first row of the X data (from attached image). The reason I ask is because the image being plotted is not what I expected.
I hope this makes sense and would really appreciate any help. Thanks in advance
  1 件のコメント
Stephen23
Stephen23 2015 年 6 月 9 日
編集済み: Stephen23 2015 年 6 月 9 日
This is the most useful reference in the documentation:
It explains how the fields data can be accessed, e.g. in a comma separated list:

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

採用された回答

Adam
Adam 2015 年 6 月 9 日
x = data.X
is just giving you the equivalent of
x = data(1).X
and ignoring the 2nd element of the data array.
What are you trying to plot though with imagesc? You effectively have two 111 x 101 matrices in data.X. You can pass either one of them to imagesc, but not both at the same time.
You can plot one as an alpha overlay on the other if you wish, but I don't know if that is what you are aiming for.
  2 件のコメント
Guillaume
Guillaume 2015 年 6 月 9 日
Note that the behaviour of struct.field, when struct is an array can be a bit confusing if you don't know what is going on behind the scene.
When you write struct.field, the structure array is expanded into a comma separated list struct(1).field, struct(2).field, etc.. Similar to the output list of a function, each element of the list can be assigned to a single variable.
Thus, you could do:
[x1, x2] = data.X;
which would be equivalent to
x1 = data(1).X;
x2 = data(2).X;
Tadgh Cullen
Tadgh Cullen 2015 年 6 月 9 日
That's exactly what I wanted to clear up. Thank you both

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGet Started with MATLAB についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by