MATLAB Answers

How can I order a matrix in a specific order?

조회 수: 16(최근 30일)
Jennifer Arellana
Jennifer Arellana 9 Apr 2021 15:32
댓글: Jennifer Arellana 9 Apr 2021 21:18
Hello to all,
I am working in Matlab with data of Ampl, so i am using amplapi. I have a problem when I call the matrices because when I check them I notice that the order is different, however, I need the matrices to have the same order to not have a problem with the rest of the code. Attached is how I have my data from a matrix in Ampl and how Matlab reads it. Please check the script. My question is how can I order my matrix in the order I want in Matlab?
Thank for your attention.

채택된 답변

dpb
dpb 9 Apr 2021 18:24
I've no klew what amplapi is, but if you have a text file like the first, reading it into MATLAB will not reorder it.
>> which -all amplapi
'amplapi' not found.
>>
shows it not a part of base MATLAB nor of the (relatively few) toolboxes I have installed so we don't know what it does; on top of that you showed us no code at all from which to be able to even hypothesize something.
BUT, the first file looks to be sorted by column 3, then by column 2 and column 1 whereas the second is by colun 1, 2, and 3.
So,
x=sortrows(x,[3 2 1]);
where x is a placeholder for your MATLAB variable containing the array will produce the same sorted order.

추가 답변(0개)

태그

Community Treasure Hunt

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

Start Hunting!

Translated by