Problems Sorting a Table using sortrows
Mostrar comentarios más antiguos
I have this table of data I need to sort based on the values in the 'Odometer' column. Here is the code I'm using.
%%Odometer Sort Algorithm
s2 = 'Odometer';
num_cols = size(data,2);
num_rows = size(data,1);
% Finds the 'Odometer' column
% starts at 2 so header doesn't get sorted
for k = 2:1:num_cols
s1 = data{1,k};
if strcmp(s1,s2)
break
end
end
for j = 2:1:num_rows
data{j,k} = str2double(data{j,k});
end
data = sortrows(data,k);
When I run the code, I get the following error:
Error using char
Cell elements must be character arrays.
Error in sortrows>sort_cell_back_to_front (line 135)
tmp = char(x(ndx,k));
Error in sortrows (line 87)
ndx = sort_cell_back_to_front(x_sub, col);
Error in Test (line 29)
data = sortrows(data,k);
I think this is a result of the first element in the 'Odometer' column being a char. How can I properly sort the rows below the first element??

Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Structures 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!