# how to create a struct that would have number of fields that corresponds to the number of iterations inside a loop and also automatically save this data

3 visualizzazioni (ultimi 30 giorni)
osasunmwen efosa il 13 Gen 2023
Commentato: osasunmwen efosa il 13 Gen 2023
for day = 1:7
for i = 1:length(signal)
for j = 1:36
MPE1(i,j) = signal(i,j,day) - signal(i,j,day) - kE1 * (signal(i,j,day) - signal(i,j,day));
end
end
MeanE1 = movmean(MPE1,3,'omitnan');
zero_meanE1 = MPE1(:,PRN) - MeanE1(:,PRN); %% need to save this in struct for each day
end
##### 1 CommentoMostra -1 commenti meno recentiNascondi -1 commenti meno recenti
Stephen23 il 13 Gen 2023
"how to create a struct that would have number of fields that corresponds to the number of iterations..."
So many fields... complex.
Simpler: non-scalar structure, cell array, numeric array...

Accedi per commentare.

### Risposta accettata

Jan il 13 Gen 2023
Result = struct();
for day = 1:7
% No loop needed:
MPE1 = signal(:, :, day) - signal(:, :, day) - kE1 * (signal(:, :, day) - signal(:, :, day));
MeanE1 = movmean(MPE1, 3, 'omitnan');
zero_meanE1 = MPE1(:,PRN) - MeanE1(:,PRN);
Result(day).zmE1 = zero_meanE1;
% Or:
% Result.zmE1{day} = zero_meanE1;
end
save('Result.mat', 'Result');
##### 1 CommentoMostra -1 commenti meno recentiNascondi -1 commenti meno recenti
osasunmwen efosa il 13 Gen 2023
Thanks alot

Accedi per commentare.

### Categorie

Scopri di più su Structures in Help Center e File Exchange

R2022b

### Community Treasure Hunt

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

Start Hunting!

Translated by