using index to assign an element

hello, I have this:
hjj = [0.6 0.4 0.9 0.7;0.8 0.7 0.9 0.5;0.8 0.6 0.5 0.4;0.8 0.5 0.6 0.5];
[weighh,idx] = sort(-sum(hjj,2));
hjx = hjj(idx,:)
[Maxx_1,idd] = max(hjx,[],2);
[Minn_1,ide] = min(hjx,[],2);
tempp = ide(1);
ide(1) = idd(2);
idd(2) = tempp...
I want to swap the position of idd(2) with ide(1), such that the new matrix becomes
[0.8 0.7 0.9 0.9;0.6 0.4 0.5 0.7;0.8 0.5 0.6 0.5;0.8 0.6 0.5 0.4]
Thanks

1 件のコメント

Jan
Jan 2017 年 8 月 26 日
編集済み: Jan 2017 年 8 月 26 日
Today I have selected the code with the mouse and hit the "{} Code" button to make the code readable. Please do this by your own in the future. Thanks.
The question is not clear, even after your comment below. Why does
0.6 0.4 0.9 0.7
0.8 0.7 0.9 0.5
0.8 0.6 0.5 0.4
0.8 0.5 0.6 0.5
get
0.8 0.7 0.9 0.9
0.6 0.4 0.5 0.7
0.8 0.5 0.6 0.5
0.8 0.6 0.5 0.4
? The given explanation matches the first 2 columns, but why does the 3rd column contains a 0.5 instead of a 0.9 after the conversion? And where does the 0.9 come from in the 4th column?
Please take the time to explain the procedure more clearly.

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

回答 (1 件)

Ennio Condoleo
Ennio Condoleo 2017 年 8 月 26 日

0 投票

Peter which goal do you want to achieve?

3 件のコメント

Peterikye
Peterikye 2017 年 8 月 26 日
My goal is to change the location of the minimum element in the upper row with the maximum element in the next lower row, until i have a situation where the minimum element in the upper row is greater than or equal to the maximum element in the next lower row. Thanks
Image Analyst
Image Analyst 2017 年 8 月 26 日
Can't you simply just use a for loop and the min() and max() functions? It's trivial.
Stephen23
Stephen23 2017 年 8 月 26 日
Use sort.

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

カテゴリ

ヘルプ センター および File ExchangeDates and Time についてさらに検索

タグ

質問済み:

2017 年 8 月 26 日

コメント済み:

2017 年 8 月 26 日

Community Treasure Hunt

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

Start Hunting!

Translated by