order using first column in array cell
Mostrar comentarios más antiguos
newList=sortrows(newList,1);
Error using matlab.internal.math.cellstrpad
Cell elements must be character arrays.
Error in sortrows>sortBackToFrontCell (line 137)
tmp = matlab.internal.math.cellstrpad(A(I,ack));
Error in sortrows (line 77)
I = sortBackToFrontCell(A, col);
Respuesta aceptada
Más respuestas (2)
Walter Roberson
el 20 de Jul. de 2024
sort_order = sort(newList(:,1));
newList = newList(sort_order,:);
1 comentario
shamal
el 20 de Jul. de 2024
Fixed code below. Read comments for explanation.
s = load('matlab_cell.mat');
originalList = s.newList
% The problem with sorting is that some cells in column 1 contain strings
% while other cells contain character arrays -- they different!
% Convert strings in column 1 into character arrays so that sortrows will work.
for row = 1 : height(originalList)
% Copy the other columns as is.
newList(row, :) = originalList(row, :);
thisCellContents = originalList{row, 1};
if isstring(thisCellContents)
% If it's a string (double quotes) turn it into a character array (single quotes).
thisCellContents = char(thisCellContents);
newList{row, 1} = thisCellContents;
end
end
% Sort the new list, not the original list.
sortedCellArray = sortrows(newList, 1)
Categorías
Más información sobre Cell Arrays en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!