how can i use a loop to run the specific code

If there are number of datafiles in the current folder, how can i use a loop to run the specific code? attaching the code. the folder name is 2002. and data file names are 200201,200202,200203 etc. I need a single matrix giving the Q values for all the data files.
data_Wwind=netcdf('E:\data\2002\200201.nc'); % input address of data folder
cot=data_Wwind{'M2TMNXRAD_5_12_4_TAUHGH'}(:);
th5 = cot > 5;
B = double(th5);
Q=sum(B(:) == 1);

 Respuesta aceptada

KSSV
KSSV el 18 de Abr. de 2022
ncFiles = dir('E:\data\2002\*.nc')
N = length(ncfiles) ;
Q = zeros(N,1) ;
for i = 1:N
ncFile = fullfile(ncFiles(i).folder,ncFiles(i).name) ;
cot=data_Wwind{'M2TMNXRAD_5_12_4_TAUHGH'}(:);
th5 = cot > 5;
B = double(th5);
Q(i)=sum(B(:) == 1);
end

6 comentarios

Joydeb Saha
Joydeb Saha el 18 de Abr. de 2022
Here data_Wwind is undefined. Can we make data_Wwind run for each of the data files and have the Q?
KSSV
KSSV el 18 de Abr. de 2022
It seems you have to extract it from netcdf file.....You have not specified it in your question, how you have got that variable.
Joydeb Saha
Joydeb Saha el 18 de Abr. de 2022
data_Wwind=netcdf('E:\Cirrus Work\new\COTdata\2002\200208.nc'); % input address of data folder
This line to be inserted for all the files in the loop
Joydeb Saha
Joydeb Saha el 18 de Abr. de 2022
I have mentioned that variable in the first line.
This is not a problem.....you can do it...
data_Wwind=netcdf(ncFile);
ncFiles = dir('E:\data\2002\*.nc');
N = length(ncFiles) ;
Q = zeros(N,1) ;
for i = 1:N
ncFile = fullfile(ncFiles(i).folder,ncFiles(i).name) ;
data_Wwind=netcdf(ncFile);
cot=data_Wwind{'M2TMNXRAD_5_12_4_TAUHGH'}(:);
th5 = cot > 3;
B = double(th5);
Q(i)=sum(B(:) == 1);
end
I have used this code to find the total number of pixels those are above threshold 3 for all the data files in the folder. How can I find the mean value of cot for all the data files only for the pixels those are above threshold three(3)?

Iniciar sesión para comentar.

Más respuestas (1)

Categorías

Más información sobre Loops and Conditional Statements en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 18 de Abr. de 2022

Comentada:

el 10 de Mayo de 2022

Community Treasure Hunt

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

Start Hunting!

Translated by