How to calculate norm for multiple .csv in different folders?

7 ビュー (過去 30 日間)
Tim K
Tim K 2021 年 5 月 20 日
コメント済み: Tim K 2021 年 5 月 21 日
Hi,
I have 10 folders with different numbers of .csv files and want to calculate the norm for every single .csv file. But the code i use only calculates the norm for a whole folder and not for every .csv in a folder (hope you get my point). So i get 10 values for norm but it should be much more.
clear all
close all
%%
anfang = [2,2,8,3,5,5,3,5,4,4];
ordern = {'00_00','00_01','01_00','01_01' '02_00' , '02_01' , '03_00' , '03_01','04_00','04_01'};
for idx3 = 1 : length(ordern)
filename = dir(fullfile(ordern {idx3},'*.csv'));
for idx2 = 1 : length(filename)
filename_cell{idx2} = filename(idx2).name;
end
filename_sort = natsortfiles(filename_cell);
for idx1 = 1 : length(filename_cell)
Data = readtable(fullfile(ordern {idx3},filename_sort{idx1}));
Data = table2array(Data);
y {idx3}= Data(:,1);
T(:,idx1) = Data(:,2);
end
%%
Tnorm {idx3} = norm(T(:,anfang(idx3):end));
clear T filename_cell filename_sort Data filename
end
  1 件のコメント
Jan
Jan 2021 年 5 月 20 日
Neither the initial clear all nor the clearing inside the loop are useful in Matlab, but they waste time only.

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

回答 (1 件)

Jan
Jan 2021 年 5 月 20 日
編集済み: Jan 2021 年 5 月 20 日
norm() calculates a matrix norm, if you provide a matrix as input. so you get a scalar output.
Maybe you want to use vecnorm instead:
Tnorm {idx3} = vecnorm(T(:,anfang(idx3):end), 2, 2);
% or maybe 1 here ^ as dimension?

カテゴリ

Help Center および File ExchangePerformance and Memory についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by