Better work through indecies in a for loop
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Poison Idea fan
le 13 Sep 2022
Commenté : Poison Idea fan
le 13 Sep 2022
I use a for loop to compute the absorption of aerosol particles in time series data. I indicate the start and stop of sample time with indecies stored in two arrays. When I compute the absorption I average four minutes of filter time and I do it based on going backwards in index. I run into a problem when the filter time isn't long enough to go back four minutes in time. My work around is using an if statement but it seems cumbersome to do it the way I have below. Is there a better way to do this?
The code below is just meant to be an example. I don't have a workspace small enough to upload to run the code.
for n = 1:length(start0)
if start0(n)-240 < 360 % If the filter time is not big enough then move on to the next sample time
n = n+1;
if start0(n)-240 < 360 % if the second filter time is too small move on to the third
n = n+1;
end
else
n = n;
end
absorption(start0(n):stop0(n),:) = ...
((smoothed_data_table.('Signal')(start0(n):stop0(n),:))...
-mean(smoothed_data_table.('Signal')(start0(n)-250:start0(n)-10,:),1,'omitnan'))...
./(smoothed_data_table.('power')(start0(n):stop0(n),:) .* mic_cal);
ext(start0(n):stop0(n),:) = (rL(1,:)/c).* ...
((smoothed_data_table.('Tau')(start0(n):stop0(n),:).^-1)...
-(mean(smoothed_data_table.('Tau')(start0(n)-250:start0(n)-10,:),'omitnan')).^-1);
end
0 commentaires
Réponse acceptée
David Hill
le 13 Sep 2022
Just use continue.
for n = 1:length(start0)
if start0(n)-240 < 360 % If the filter time is not big enough then move on to the next sample time
continue;
end
absorption(start0(n):stop0(n),:) = ...
((smoothed_data_table.('Signal')(start0(n):stop0(n),:))...
-mean(smoothed_data_table.('Signal')(start0(n)-250:start0(n)-10,:),1,'omitnan'))...
./(smoothed_data_table.('power')(start0(n):stop0(n),:) .* mic_cal);
ext(start0(n):stop0(n),:) = (rL(1,:)/c).* ...
((smoothed_data_table.('Tau')(start0(n):stop0(n),:).^-1)...
-(mean(smoothed_data_table.('Tau')(start0(n)-250:start0(n)-10,:),'omitnan')).^-1);
end
Plus de réponses (0)
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!