Borrar filtros
Borrar filtros

Better work through indecies in a for loop

1 visualización (últimos 30 días)
Poison Idea fan
Poison Idea fan el 13 de Sept. de 2022
Comentada: Poison Idea fan el 13 de Sept. de 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

Respuesta aceptada

David Hill
David Hill el 13 de Sept. de 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

Más respuestas (0)

Categorías

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

Productos


Versión

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by