Multiple outputs of a single function in a single array

Hi,
I am trying for the maximum value of each column of an excel file (total 63 columns).
stress=xlsread('output.xlsx','sheet1')
for i=1:1:63
x=max(s(:,i))
end
This gives me an output as
s=
123
s=
345
s=
232
How can I get all the output values in a single array as
s=
123
345
232.
Also, when I terminate the function with ";" at s=max(s(:,i));
and try to get the output in the command window, it is giving me just the last result 232.
How can I get the results in a single column even when I terminate the statement?
Thanks.

 Respuesta aceptada

Stephen23
Stephen23 el 13 de Sept. de 2018
Editada: Stephen23 el 13 de Sept. de 2018
N = 8;
C = cell(1,N);
for k = 1:N
S = xlsread('output',sprintf('sheet%d',k));
C{k} = max(S,[],1).';
end
M = [C{:}]
This is just based on the examples in the MATLAB documentation:

1 comentario

It worked great.
Also referred to the link provided.
Thanks mate!

Iniciar sesión para comentar.

Más respuestas (1)

x(i) =max(s(:,i));
Or you can skip the loop and use the single statement
x = max(s);
max automatically takes the maximum along each column.

5 comentarios

JAGAN MOHAN KUMMARI
JAGAN MOHAN KUMMARI el 13 de Sept. de 2018
Editada: JAGAN MOHAN KUMMARI el 13 de Sept. de 2018
Tried them both, however, they both give values as
Columns 1 through 3
123 345 232
Columns 4 through 6
321 543 323
Columns 7 through 9...
so just wondering if there is a way I can get them all in a single column without any text in between.
Thanks
Awesome! Got it.
s1=xlsread('output','Sheet1')
s2=xlsread('output','Sheet2')
...
x1=max(s1);
x2=max(s2);
...
s=[s1' s2'....]
Thanks mate!
Stephen23
Stephen23 el 13 de Sept. de 2018
@JAGAN MOHAN KUMMARI: using numbered variables is a sign that you are doing something wrong. A loop is the better solution, allocating the output into a preallocated array.
Hi Stephen,
Actually, I am reading multiple sheets of a file for a similar result from each sheet. I should learn more of programming skills to make life easy.
Tried your comment. Its giving answers for the first sheet.
The problem: 8 Sheets of an excel file, each sheet has 63 columns. I want the maximum value of each column of a sheet as a single column, along with 7 other columns of maximum values of the remaining 7 sheets.
I have written it this way
s1=xlsread('output','Sheet1')
s2=xlsread('output','Sheet2')
...
s8=xlsread('output','Sheet8')
x1=max(s1);
x2=max(s2);
...
x8=max(s8);
s=[s1' s2'....s8']
Would be thankful to make it simpler.
Thanks.

Iniciar sesión para comentar.

Categorías

Más información sobre Loops and Conditional Statements en Centro de ayuda y File Exchange.

Preguntada:

el 13 de Sept. de 2018

Comentada:

el 13 de Sept. de 2018

Community Treasure Hunt

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

Start Hunting!

Translated by