Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

could anyone help me to solve the error in the following code

조회 수: 1 (최근 30일)
jaah navi
jaah navi 2019년 8월 1일
마감: MATLAB Answer Bot 2021년 8월 20일
I am having the following matrix
A=[0.2288 0.2193 0.2082 0.1961 0.1832 0.1699;
1.1237 1.0564 0.9837 0.9092 0.8392 0.7826;
0.0451 0.0401 0.0331 0.0245 0.0152 0.0092;
0.8840 0.9053 0.9243 0.9396 0.9501 0.9548;
0.1320 0.1442 0.1545 0.1628 0.1689 0.1731]
I want to find two maximum values in each column
so i tried with the following code:
max_values = 2;
[v1,idx1]=sort(A,1,'descend');
W1 = zeros(size(A));
W1(sub2ind(size(A),repmat((1:size(A,2)).',...
1,2),idx(:,1:max_values))) = v1(:,1:max_values)
when i run the code i am getting error stating Error using sub2ind The subscript vectors must all be of the same size.
Could anyone please help me on this.
  댓글 수: 6
Alex Mcaulley
Alex Mcaulley 2019년 8월 1일
I totally agree Madhan XD. Maybe it is useful for other readers
madhan ravi
madhan ravi 2019년 8월 1일
Alex that's completely true though :)

답변 (1개)

KALYAN ACHARJYA
KALYAN ACHARJYA 2019년 8월 1일
편집: KALYAN ACHARJYA 2019년 8월 1일
"I want to display first two maximum vaues in each column"
out=sort(A(:,:),'descend');
data=out(1:2,:)
Result:
data =
1.1237 1.0564 0.9837 0.9396 0.9501 0.9548
0.8840 0.9053 0.9243 0.9092 0.8392 0.7826
  댓글 수: 9
KALYAN ACHARJYA
KALYAN ACHARJYA 2019년 8월 1일
Thank you @Walter and @Madhan

이 질문은 마감되었습니다.

태그

제품


릴리스

R2015a

Community Treasure Hunt

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

Start Hunting!

Translated by