Borrar filtros
Borrar filtros

How to manipulate some data inside a structure array?

7 visualizaciones (últimos 30 días)
Virgilio Grigiotti
Virgilio Grigiotti el 30 de Abr. de 2021
Comentada: Mario Malic el 1 de Mayo de 2021
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 comentario
Mario Malic
Mario Malic el 1 de Mayo de 2021
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.

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Structures en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by