for-loop over Structure Array
Ältere Kommentare anzeigen
Hello together,
I am currently working with multiple experimental datasets containing velocitys of different fluid components and pressure losses. One of those datasets is contained in a structure with fields containing the experimental data as arrays.
My task ist to calculate the same dimensionless numbers for every dataset from the presure losses, densities, velocities, etc. I have written a loop over all structures grouped to an array, however calculations are only saved to the index (i) of the loop , not to the original structures in the array. So only the last calculation is saved. I suspect the calculations are running correctly inside the loop but don't get saved to the right output structure.
Code:
A=load('dataset1.mat'); %saved workspace with dataset1
B=load('dataset2.mat'); %saved workspace with dataset2
% and so on
A.vel1 %returns 15x1 double
A.vel2 %returns 15x1 double
B.vel1 %returns 24X1 double
B.vel2 %returns 24x1 double
A.rho=997; %additional data
B.rho=876;
%and so on
for i=[A,B]: %loop over all datasets
i.f1=i.rho*i.vel1;
%and so on
end
A.f %Error: Reference to non-existent field 'f'
B.f %Error: Reference to non-existent field 'f'
i.f %returns 24x1 double with right values B.rho*B.vel1
Can anybody exlpain to me, why this happens and how I can fix it, so that all calculations are computed and saved in A and B?
Thank you for your help!
1 Kommentar
KSSV
am 11 Feb. 2020
You should attach your dataset files also.
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!