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 endendfor j = 2:1:num_rows data{j,k} = str2double(data{j,k});enddata = sortrows(data,k);
When I run the code, I get the following error:
Error using charCell 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??
Best Answer