Borrar filtros
Borrar filtros

execute a script in a loop

6 visualizaciones (últimos 30 días)
Ahmed Alsaadi
Ahmed Alsaadi el 21 de Nov. de 2018
Editada: Stephen23 el 26 de Abr. de 2021
I have made a script that calculates FFT, STFT, Wigner-Ville, etc. The inputs are file1.csv, file2.csv,file3.csv, etc. The script executes the inputs and gives me outputs, the outputs are crossponding to the input i.e output1, output2, output3, etc.
I want to create a loop that import the input files (file1.csv, file2.csv, etc) and executes them consecutively and save the output in a matrix, each column in the matrix represents an output i.e. column1 is output1 and colum2 is output 2 etc.

Respuesta aceptada

Stephen23
Stephen23 el 22 de Nov. de 2018
Editada: Stephen23 el 26 de Abr. de 2021
"The script executes the inputs and gives me outputs, the outputs are crossponding to the input i.e output1, output2, output3, etc."
Magically defining/accessing variable names is one way that beginners force themselves into writing slow, complex, buggy code that is hard to debug. Read this to know why:
Basically your bad data design willl force you into writing pointlessly slow, complex, and buggy code, but you can easily avoid this by designing your data better: do NOT have lots of separate numbered variables!
You can simply collect all of the data into one array (e.g. a cell array) inside the loop, for example:
N = 20;
C = cell(1,N);
for k = 1:N
output = ... your code
C{K} = output;
end
M = [C{:}];
plot(M)
You can easily loop over those files too, e.g.:
S = dir('*.csv');
S = natsortfiles(S); % download from FEX.
for k = 1:numel(S)
S(k).data = csvread(S(k).name); % use filename
end
M = [S.data]
This will be much simpler, more effiicent, and easier to debug than any code you could write with magically accessed variable names!
  1 comentario
Ahmed Alsaadi
Ahmed Alsaadi el 22 de Nov. de 2018
Both work well, thank you very much.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Fourier Analysis and Filtering en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by