Could anyone help me to solve the issue in the following code

code:
unused_rows=1:12
while ~isempty(unused_rows)
rows_matrix=reshape(unused_rows,[],2)
rows_matrix(:,end)=rows_matrix(end:-1:1,end)
for k=1:size(rows_matrix,1)
rows=rows_matrix(k,:)
unused_rows=[];
end
end
The above code executes and gives me the result.
with respect to the command line
rows_matrix=reshape(unused_rows,[],2)
I am getting the result to be
rows_matrix =
1 7
2 8
3 9
4 10
5 11
6 12
But I want to display the result in the following manner.
rows_matrix =
1 9
2 8
3 7
4 12
5 11
6 10
Could anyone please help me on this.

 Akzeptierte Antwort

Raj
Raj am 8 Jul. 2019
Bearbeitet: Raj am 8 Jul. 2019
May not be the best way but it works:
rows_matrix=reshape(unused_rows,[],2)
rows_matrix=[rows_matrix(:,1) [sort(rows_matrix(1:3,2),'descend');sort(rows_matrix(4:6,2),'descend')]]

3 Kommentare

with respect to code
unused_rows=1:12
rows_matrix=reshape(unused_rows,[],3)
rows_matrix(:,end)=rows_matrix(end:-1:1,end)
i am getting the following result with respect to the command line
rows_matrix=reshape(unused_rows,[],3)
rows_matrix =
1 5 9
2 6 10
3 7 11
4 8 12
and with respect to the command line
rows_matrix(:,end)=rows_matrix(end:-1:1,end)
rows_matrix =
1 5 12
2 6 11
3 7 10
4 8 9
But i want to have the result in the following manner
rows_matrix =
1 5 10
2 6 9
3 7 12
4 8 11
Could you help me on this.
I would say again using the same thought process :
unused_rows=1:12
rows_matrix=reshape(unused_rows,[],3)
rows_matrix(:,end)=rows_matrix(end:-1:1,end)
rows_matrix=[rows_matrix(:,1) rows_matrix(:,2) [sort(rows_matrix(3:4,3),'descend');sort(rows_matrix(1:2,3),'descend')]]
I too tried with the same command by yesterday itself .Anyway thanks for your reply

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu MATLAB finden Sie in Hilfe-Center und File Exchange

Tags

Gefragt:

am 8 Jul. 2019

Kommentiert:

am 9 Jul. 2019

Community Treasure Hunt

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

Start Hunting!

Translated by