How to read matrix data in a loop

3 ビュー (過去 30 日間)
Sameer Ingale
Sameer Ingale 2023 年 2 月 3 日
編集済み: Voss 2023 年 2 月 3 日
I have one variable name 'T1' it has 1x327 cell and each cell contain 19200x14. I want to read each data from T1 oen by one in a loop.
myFolder = 'D:\Finall Sorted data\Task 1';
% Get a list of all files in the folder with the desired file name pattern.
filePattern = fullfile(myFolder, '*.csv');
theFiles = dir(filePattern);
n = length(theFiles);
for k = 1 : n
baseFileName = theFiles(k).name;
T1{k} = readmatrix(fullfile(theFiles(k).folder, baseFileName));
end
for i = 1 : 327
{
T1i} = T1{1,i}
Incorrect use of '=' operator. Assign a value to a variable using '=' and compare values for equality using '=='.
};
end

採用された回答

Voss
Voss 2023 年 2 月 3 日
You already have all the data from all the files, stored in T1.
You can remove this loop:
for i = 1 : 327
{
T1i} = T1{1,i}
};
end
and just refer to T1{1}, T1{2}, etc., later in the code when you need to process the contents of each cell of T1. Example:
for i = 1 : n
% do something with T1{i}
current_mean = mean(T1{i},1); % whatever
end
  2 件のコメント
Sameer Ingale
Sameer Ingale 2023 年 2 月 3 日
Thank you so much
Voss
Voss 2023 年 2 月 3 日
編集済み: Voss 2023 年 2 月 3 日
You're welcome! Any questions, let me know.

サインインしてコメントする。

その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by