Matrix with one numbers column and one strings column.
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Ok, so I have a for loop which returns me, for every file I read from a folder, the name of the file and some values I read from the file. I need to create a matrix with the first column containing the value from every specific file and the secound column should contain the name of the file from which that value was read. I need to sort those files descending by the values from each one of them.
Let's say I have three files: '1.txt', '2.txt', '3.txt'.
I read 1 from '1.txt', 5 from '2.txt' and 3 from '3.txt'. The final matrix should be like this [1 1.txt; 3 3.txt; 5 2.txt]
I hope I made myself clear.
0 Kommentare
Antworten (1)
Jos (10584)
am 14 Jul. 2015
You can use cell arrays for this, which can hold a mixture of types. Each cell contains something, possibly another cell array. To get a specific cell, use the standard notation with round brackets. To get the content of a cell, use curly brackets
C = {1 '1.txt' ; 2 '2.txt'}
OneCell = C(2,1)
Content = C{2,1}
2 Kommentare
Walter Roberson
am 15 Jul. 2015
You can sort a column of a cell array and request the sort order as an output. You can then use the sort order to index the entire cell array.
[~, sortidx] = sort([A{:,1}]);
sortedA = A(sortidx,:);
Siehe auch
Kategorien
Mehr zu Shifting and Sorting Matrices finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!