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.

 Respuesta aceptada

KSSV
KSSV el 4 de Ag. de 2021
Editada: KSSV el 4 de Ag. de 2021
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 comentarios

Patrick Lonergan
Patrick Lonergan el 4 de Ag. de 2021
It gave the following error
KSSV
KSSV el 4 de Ag. de 2021
y is a table, it cannot be saved into array so error popped out. Why you are runnng calculation on table, you can go for array indexing right.
Patrick Lonergan
Patrick Lonergan el 4 de Ag. de 2021
Do you suggest just to use an array in the sum line?
Patrick Lonergan
Patrick Lonergan el 4 de Ag. de 2021
I am not too sure what you mean

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Productos

Versión

R2021a

Preguntada:

el 4 de Ag. de 2021

Comentada:

el 4 de Ag. de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by