Creating an array of maximum values from differents tables

I have 5 tables 2000x5 and want to create an array consisting of maximum values from the column 5 of all tables. This was my attempt:
for N_arq = [23 21 19 17];
s = readtable(strcat('r',num2str(N_arq),'.csv'),'Headerlines',1);
C5C = table2array(s(:,5));
AC = max(C5R(300:end))
end
But, this overwrite the last data on AC and don't create the desired array.

1 件のコメント

Walter Roberson
Walter Roberson 2025 年 3 月 19 日
C5C = table2array(s(:,5));
Easier is
C5C = s{:,5};
or
C5C = s.(5);

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

 採用された回答

Star Strider
Star Strider 2025 年 3 月 19 日

0 投票

Your current code creates the variable ‘CSC’ and then takes the maximum of selected rows of ‘C5R’. I changed that, although nothing else.
I assume all the .csv files are already available in your default path.
Try this —
N_arqv = [23 21 19 17];
for k = 1:numel(N_arqv)
N_arq = N_arqqv(k)
s = readtable(strcat('r',num2str(N_arq),'.csv'),'Headerlines',1);
C5C = table2array(s(:,5));
AC(k,:) = max(C5C(300:end))
end
Result = table(AC, VariableNames=["Col 5 Maximum"])
Make appropriate changes to get the desired result.
.

3 件のコメント

Luis
Luis 2025 年 3 月 19 日
Yes, I have all the .csv in default path.
Thanks for the help.
Star Strider
Star Strider 2025 年 3 月 19 日
As always, my pleasure!
Star Strider
Star Strider 2025 年 3 月 19 日
A tweak —
N_arqv = [23 21 19 17];
for k = 1:numel(N_arqv)
N_arq = N_arqqv(k)
rn{k} = sprintf('r%d',N_arq);
s = readtable(strcat('r',num2str(N_arq),'.csv'),'Headerlines',1);
C5C = table2array(s(:,5));
AC(k,:) = max(C5C(300:end))
end
Result = table(AC, VariableNames={'Col 5 Maximum'}, RowNames=rn)
This gives each file (without the .csv extensiion, although you can add that if you want) as its appropriate row name in the ‘Results’ table. I just now thought to include that.
.

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeTables についてさらに検索

製品

リリース

R2023b

タグ

質問済み:

2025 年 3 月 19 日

コメント済み:

2025 年 3 月 19 日

Community Treasure Hunt

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

Start Hunting!

Translated by