set matrix m x n

1 次查看(过去 30 天)
Faustino Quintanilla
评论: Jan 2017-12-2
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 个评论
Rik
Rik 2017-12-1
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
Each of the variables may vary from 0 to 5 numeric value. I am looking for the maximum of each row.

请先登录,再进行评论。

回答(1 个)

Jan
Jan 2017-12-2
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 个评论
Rik
Rik 2017-12-2
A = [XfmrpfCH', XfmrpfCT', XfmrpfCL', XfmrpfCHLUST', ...
XfmrpfCHTUST', XfmrpfCLTUST'];
Amax = max(A, 2)
Jan
Jan 2017-12-2
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.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by