How can I order a matrix in a specific order?

2 visualizzazioni (ultimi 30 giorni)
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.

Risposta accettata

dpb
dpb il 9 Apr 2021
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.

Più risposte (0)

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by