필터 지우기
필터 지우기

Running a loop of inputting tables into MatLab

조회 수: 4 (최근 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개)

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by