フィルターのクリア

for loop to read different files

11 ビュー (過去 30 日間)
Gemma
Gemma 2023 年 1 月 20 日
回答済み: Sulaymon Eshkabilov 2023 年 1 月 21 日
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

回答 (1 件)

Sulaymon Eshkabilov
Sulaymon Eshkabilov 2023 年 1 月 21 日
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

カテゴリ

Help Center および File ExchangeWhos についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by