Accessing data within astructure
Información
La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.
Mostrar comentarios más antiguos
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.
Respuestas (2)
Amit
el 19 de En. de 2014
0 votos
you can access each array as anotace.borders.Y{i} where i is the i'th array in the structure.
4 comentarios
Amit
el 19 de En. de 2014
Also, lets say you're try to create variables in a sequence like val1, val2 and blah ..
you can do something like
for ii = length(anotace.borders.Y)
eval(['val' num2str(ii) '=anotace.borders.Y{' num2str(ii) '}']);
end
Jan
el 19 de En. de 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
el 19 de En. de 2014
@Amit: Using EVAL to create variables dynamically is a very bad programming practize and there is always a better solution.
Jan
el 19 de En. de 2014
data = {anotace.borders.Y};
data{1}
data{2}
La pregunta está cerrada.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!