Info

La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.

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

1 visualización (últimos 30 días)
jaah navi
jaah navi el 1 de Ag. de 2019
Cerrada: MATLAB Answer Bot el 20 de Ag. de 2021
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 comentarios
Alex Mcaulley
Alex Mcaulley el 1 de Ag. de 2019
I totally agree Madhan XD. Maybe it is useful for other readers
madhan ravi
madhan ravi el 1 de Ag. de 2019
Alex that's completely true though :)

Respuestas (1)

KALYAN ACHARJYA
KALYAN ACHARJYA el 1 de Ag. de 2019
Editada: KALYAN ACHARJYA el 1 de Ag. de 2019
"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 comentarios
KALYAN ACHARJYA
KALYAN ACHARJYA el 1 de Ag. de 2019
Thank you @Walter and @Madhan

La pregunta está cerrada.

Etiquetas

Productos


Versión

R2015a

Community Treasure Hunt

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

Start Hunting!

Translated by