add each iteration of for loop to a table

조회 수: 12 (최근 30일)
Patrick Lonergan
Patrick Lonergan 2021년 8월 4일
댓글: Patrick Lonergan 2021년 8월 4일
Hi,
I have the following code;
f=dir('*.csv');
for i=1:length(f)
x=readtable(f(i).name)
y=[sum(x.LogicRate100),sum(x.LogicRate125),sum(x.LogicRate150),sum(x.LogicRate170),sum(x.LogicPower50),sum(x.LogicPower66),sum(x.LogicPower75),sum(x.LogicPower80)]
y=array2table(y)
writetable(y,['out' num2str(i) '.csv']);
end
It reads each file in the and sums the 8 collumns to produce a vairale (y).
I want the output to be a table or array that each row contains the output of each iteration. Currently, I am just saving each row.

채택된 답변

KSSV
KSSV 2021년 8월 4일
편집: KSSV 2021년 8월 4일
f=dir('*.csv');
T = zeros(length(f),[]) ;
for i=1:length(f)
x=readtable(f(i).name)
y=[sum(x.LogicRate100),sum(x.LogicRate125),sum(x.LogicRate150),sum(x.LogicRate170),sum(x.LogicPower50),sum(x.LogicPower66),sum(x.LogicPower75),sum(x.LogicPower80)]
y=array2table(y)
T(i,:) = table2array(y) ;
end
writematrix(T,'test.csv')
  댓글 수: 4
Patrick Lonergan
Patrick Lonergan 2021년 8월 4일
Do you suggest just to use an array in the sum line?
Patrick Lonergan
Patrick Lonergan 2021년 8월 4일
I am not too sure what you mean

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Multidimensional Arrays에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by