finde some maximum values of matrix without collision!!!!

3 ビュー (過去 30 日間)
hadi mostafavi amjad
hadi mostafavi amjad 2018 年 10 月 2 日
編集済み: Rik 2018 年 10 月 7 日
hi, i have 4*6 random matrix and i want to select a maximum value of each rows, but the problem is, before selecting the max value of each rows it looks to orginal index of previous row’s maximum value!!! and if it’s in the same place it go for 2nd maximum value and select it. and do this 4 time.

回答 (2 件)

Rik
Rik 2018 年 10 月 2 日
I suspect there is a better way with the sort function, but I can't come up with now. This should work.
data=rand(4,6);
maxlist=zeros(size(data,1),1);
temp_data=data;
for n=1:numel(maxlist)
current_row_max=max(temp_data(n,:));
temp_data(ismembertol(temp_data,current_row_max))=NaN;
maxlist(n)=current_row_max;
end
  2 件のコメント
hadi mostafavi amjad
hadi mostafavi amjad 2018 年 10 月 3 日
hi and thanks for answering??,but your codes find the maximum values of each rows and show them for me, but i want to do it, if an array and another array (in 2 different rows)are in the same column it select the second maximum value of the second row!
Rik
Rik 2018 年 10 月 3 日
編集済み: Rik 2018 年 10 月 7 日
Can you give an example of what you mean? Because I don't understand what you want to happen.

サインインしてコメントする。


Bruno Luong
Bruno Luong 2018 年 10 月 3 日
A = ceil(5*rand(4,6))
B = A;
m = size(B,1);
c = zeros(m,1);
maxA = zeros(m,1);
r = (1:m)';
for i=1:m
[maxA(i),c(i)] = max(B(i,:));
if (i < m)
B(i+1,c(i)) = -Inf;
end
end
% 3-column array: row column and value
[r,c,maxA]

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by