Effacer les filtres
Effacer les filtres

execute a script in a loop

6 vues (au cours des 30 derniers jours)
Ahmed Alsaadi
Ahmed Alsaadi le 21 Nov 2018
Modifié(e) : Stephen23 le 26 Avr 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.

Réponse acceptée

Stephen23
Stephen23 le 22 Nov 2018
Modifié(e) : Stephen23 le 26 Avr 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 commentaire
Ahmed Alsaadi
Ahmed Alsaadi le 22 Nov 2018
Both work well, thank you very much.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Fourier Analysis and Filtering dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by