for loop to read different files
8 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I'm trying to run a for loop to read 3 different files loaded already on my workspace. Add the values on file 1 to file 2. Extract from another file the data and add +600, add that new data to an array and plot it. Any help with the code for this is really appreciated!
Something like this:
for j=1 numFiles
***read file 1
***read file 2
***add file 1 to file 2
***extract file 3 (new data +600)
*** add that chunk of data to an array
end
plot new chunk of data
0 commentaires
Réponses (1)
Sulaymon Eshkabilov
le 21 Jan 2023
There are a few different ways that can do this exercise. Here is one of them:
clearvars
FILE = fullfile('C:\Users\...', '*.txt'); % Directory where the files are residing. Your data file extension, e.g.: .txt, .xlsx, .csv, etc
LIST = dir(FILE);
N = length(LIST); % N = data files
D = zeros(1e3, 1e3, N);
for ii = 1 : N
FFName = fullfile(LIST(ii).folder, LIST(ii).name);
DATA = readmatrix(FFName);
D(:, :, ii) = DATA; % NOW D contains all data from N files
end
plot() % Select and process the part of D that is necessary
You can adjust this shown loop code for three different files
0 commentaires
Voir également
Catégories
En savoir plus sur Loops and Conditional Statements 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!