Info

This question is closed. Reopen it to edit or answer.

Accessing data within astructure

1 view (last 30 days)
Jan
Jan on 19 Jan 2014
Closed: MATLAB Answer Bot on 20 Aug 2021
Hello,
I am trying to access data from a part of a structure, which I have not implemented myself.
It looks like:
>> whos
Name Size Bytes Class Attributes
anotace 1x1 2648 struct
then:
anotace.borders
ans =
1x5 struct array with fields:
Y
H
type
>> anotace.borders.Y
ans =
106.0000 106.0000 164.5000 164.5000
685.2500 733.2500 733.2500 685.2500
ans =
368.5000 368.5000 440.5000 440.5000
604.2500 661.2500 661.2500 604.2500
ans =
351.5448 351.5448 421.5945 421.5945
461.3955 521.8930 521.8930 461.3955
ans =
356.3209 356.3209 432.7388 432.7388
306.9677 369.0572 369.0572 306.9677
ans =
337.2164 337.2164 423.1866 423.1866
192.3408 252.8383 252.8383 192.3408
I would like to access anotace.borders.Y and use its data as an array of arrays(each ans as one array). When I try to assign its value I only get the first ans into my new variable.
Thanks for help.

Answers (2)

Amit
Amit on 19 Jan 2014
you can access each array as anotace.borders.Y{i} where i is the i'th array in the structure.
  4 Comments
Amit
Amit on 19 Jan 2014
Edited: Amit on 19 Jan 2014
My bad. anotace.borders is the struct with fields Y. Try this. This will work.
for ii = 1:5
eval(['val' num2str(ii) '=anotace.borders(' num2str(ii) ').Y']);
end
Jan
Jan on 19 Jan 2014
@Amit: Using EVAL to create variables dynamically is a very bad programming practize and there is always a better solution.

Jan
Jan on 19 Jan 2014
data = {anotace.borders.Y};
data{1}
data{2}

Community Treasure Hunt

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

Start Hunting!