How to manipulate some data inside a structure array?

7 次查看(过去 30 天)
Hi all,
I have to calculate some areas from some different hydraulic cross section datasets, i think it won't be a problem with trapz function. With a help i managed to build a structure array "called" sections where there are all the cross sections as field and another substructure as a value with station and elevation data of the hydraulic cross section
When i try to calculate minimum elevation (inside a for cycle used to extract data from a .gxx file) i manage to see the loop with all the elevation data in the command window but in the workspace the variable is only the last value of the matlab calculation
The struct is written in this way: Sezioni.(sez_name).station = sez1(:,2)'
sez_name is composed by 191 "char" fields with name of the c.s., the value is another 1x1 structure with station (x) and elevation (y) data. I have to calculate the minimum elevation for all fields, not only for the last. How can I do? Thank you for the help.
  1 个评论
Mario Malic
Mario Malic 2021-5-1
Hey Virgilio,
When you ask for some inputs from structure, there are cases where the output will result in something like this
data = struct();
tempstruc = struct('a', [1; 2], 'b', [2; 3]);
data.a(1).station = tempstruc;
data.a(2).station = tempstruc;
data.b.station = [2 3 4;
1 4 5];
[data.a.station]
ans = 1×2 struct array with fields:
a b
data.a.station
ans = struct with fields:
a: [2×1 double] b: [2×1 double]
ans = struct with fields:
a: [2×1 double] b: [2×1 double]
If you see the last line, this is how your output looks like, ans is being constantly replaced and your next line will only take the last value for it.
It is hard to visualize how is your structure formed. I'd suggest you to create a simpler and similar structure and try to figure out how you should do things on it.
Take a look also at functions fieldnames.

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Structures 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by