Running a loop of inputting tables into MatLab

8 ビュー (過去 30 日間)
Elyse
Elyse 2024 年 6 月 20 日
編集済み: Voss 2024 年 6 月 20 日
Hi, I have this code:
[data]=loadScopeData('/Volumes/usb/table_5.csv',[1,inf]);
max_col2_5=max(data.pvdf_v)
max_col3_5=max(data.cell_v)
and I have tables for each trial 5-40 and I was wondering if there was a way that I could run this in a loop so import each table (table_5, table_6, table_7...), and to find the max of each of the second two columns labeled (max_col2_5, max_col2_6, max_col2_7...) matching the number of the table, so that I can later make a table out of these values. I have bolded the numbers that would need to increase by one each time, the rest of teh script would stay the same. I am thinking that a while loop could work for this, but I'm not sure how I can integrate that into the file name when loading the data. Turning this into a loop would be a lot faster and easier to run that having this script for each trail, especially as I start doing more. Thanks.

採用された回答

Voss
Voss 2024 年 6 月 20 日
編集済み: Voss 2024 年 6 月 20 日
First generate the file names. Since you know it's trials 5-40, you can do this:
filenames = "/Volumes/usb/table_" + (5:40) + ".csv";
(If you didn't know in advance which files you'd need, you could use dir and fullfile to get the file names and then likely natsortfiles to put them in the right order.)
Then, in a loop, read each file and collect the relevant values into a matrix:
N = numel(filenames);
max_col = zeros(N,2);
for ii = 1:N
data = loadScopeData(filenames(ii),[1,inf]);
max_col(ii,1) = max(data.pvdf_v);
max_col(ii,2) = max(data.cell_v);
end
If later you want to make a table out of those values then:
T = array2table(max_col);
  2 件のコメント
Elyse
Elyse 2024 年 6 月 20 日
Thanks, this works really well!
Voss
Voss 2024 年 6 月 20 日
You're welcome!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

製品


リリース

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by