I am trying to create a matrix of 200 (rows by 6 (columns). I input by variable, but get a single row with all variable in multiple columns. The objective is to get the max of each row from the 6 columns. Can someone help me out?
h=height(PFset);
for x=1:height(PFset)
A= [XfmrpfCH XfmrpfCT XfmrpfCL XfmrpfCHLUST XfmrpfCHTUST XfmrpfCLTUST];
end

2 comentarios

Rik
Rik el 1 de Dic. de 2017
What are the sizes of the vectors you want to concatenate? Once you have the matrix, just look up the documentation for the max function. You can specify a dimension for it to operate on.
Faustino Quintanilla
Faustino Quintanilla el 2 de Dic. de 2017
Each of the variables may vary from 0 to 5 numeric value. I am looking for the maximum of each row.

Iniciar sesión para comentar.

Respuestas (1)

Jan
Jan el 2 de Dic. de 2017

0 votos

The body of the loop does not depend on the loop counter:
for x = 1:height(PFset)
A = [XfmrpfCH XfmrpfCT XfmrpfCL XfmrpfCHLUST XfmrpfCHTUST XfmrpfCLTUST];
end
This is equivalent to:
A = [XfmrpfCH XfmrpfCT XfmrpfCL XfmrpfCHLUST XfmrpfCHTUST XfmrpfCLTUST];
without any loop.
The currently provided information are not enough to guess, what you want instead. Please edit the question and add more details.

5 comentarios

Faustino Quintanilla
Faustino Quintanilla el 2 de Dic. de 2017
Here is example of what I would like to see:
  • fmrpfCH, XfmrpfCT, XfmrpfCL, XfmrpfCHLUST, XfmrpfCHTUST, XfmrpfCLTUST; max
  • 0, 0, 1, 2, 2, 5 : max 5 for row 1
  • 1, 0, 1, 0, 0, 2 : max 2 for row 2
What I am getting is a single row with no max like: 0, 0, 1, 2, 2, 5, 1, 0, 1, 0, 0, 2
Thank you ahead of time for your help.
Jan
Jan el 2 de Dic. de 2017
@Faustino: I'm sure the notation is trivial for you, but for me as a reader, who does not have the faintest idea about what you are doing, this is unclear:
fmrpfCH, XfmrpfCT, XfmrpfCL, XfmrpfCHLUST, XfmrpfCHTUST, XfmrpfCLTUST; max
Neither the cryptic names of the variables nor the explanations sheds light on what you want to achieve.
As said already: Your loop is meaningless. As long as you do not explain its intention, I cannot suggest a solution. Maybe:
If the mentioned variables are column vectors, perhaps you want:
A = [XfmrpfCH, XfmrpfCT, XfmrpfCL, XfmrpfCHLUST, ...
XfmrpfCHTUST, XfmrpfCLTUST];
Amax = max(A, 2)
Faustino Quintanilla
Faustino Quintanilla el 2 de Dic. de 2017
The reason for loop is to generate multiple row of the six variables. Currently, I have 200 entries with each variable in separate lists. I would like to combine the 6 variables into 200 rows in a single matrix, then obtain the max of each row.
However, with or without the loop the 200 entries with 6 variables using the A=[XfmrpfCH,XfmrpfCT, XfmrpfCL, XfmrpfCHLUST, XfmrpfCHTUST, XfmrpfCLTUST]; Produces a single row with 1200 columns (200x6).
Rik
Rik el 2 de Dic. de 2017
A = [XfmrpfCH', XfmrpfCT', XfmrpfCL', XfmrpfCHLUST', ...
XfmrpfCHTUST', XfmrpfCLTUST'];
Amax = max(A, 2)
Jan
Jan el 2 de Dic. de 2017
The reason for loop is to generate multiple row of the six variables.
But this loop does not do this. It creates the same matrix repeatedly, such that it is a waste of time only. Do you understand this?
Currently, I have 200 entries with each variable in separate lists.
Faustino, what are "lists"? Please stay at the standard terms. The question would have been much clearer than. Are "XfmrpfCH" and the other variables [1 x 200] vectors? Then you want either:
A = [XfmrpfCH', XfmrpfCT', XfmrpfCL', XfmrpfCHLUST', ...
XfmrpfCHTUST', XfmrpfCLTUST']
or
A = [XfmrpfCH; XfmrpfCT; XfmrpfCL; XfmrpfCHLUST; ...
XfmrpfCHTUST; XfmrpfCLTUST]
Now either max(A, [], 1) or max(A, [], 2) will find the maximum value in each column or row.

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 1 de Dic. de 2017

Comentada:

Jan
el 2 de Dic. de 2017

Community Treasure Hunt

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

Start Hunting!

Translated by