Why I'm getting AAAA... when using char??
Show older comments
So i got a list of names in an excel file, transfer them to a cell within their z-values assossiated
I want to sort the names from the least to the high z-value so what I'm doing is:
cell=char(info);
coded_names=double(info);
sorted_names=sortrows(coded_names); % as a first row of the matrix I have the z-values
Now I have everything sorted just translate the numeric code that matlab has to letters again BUT
When I do:
list=char(sorted_names);
I get a list with AAAAAA for all the names
Can someone please explain me why? I did it before and it was working
Thanks!
2 Comments
Geoff Hayes
on 30 Aug 2017
Marc - can you provide a small example for your info object that demonstrates the problem? Note that the line
cell=char(info);
seems incorrect as you are converting all data within info to characters and then calling this cell. Note that cell is a built-in MATLAB function (see cell) to create a cell array...it is never a good idea to name a variable in this manner.
Jan
on 30 Aug 2017
@Marc: The code looks confusing. "cell=char(info)" redefines the command "cell" with a variable, which is not a cell, but a char matrix. Phew. And in the next step you convert it to doubles.
What about:
sort(info)
without any conversions?
Answers (1)
Image Analyst
on 30 Aug 2017
Not sure what you're doing or what you want, but this sorts a cell array alphabetically:
words = strsplit('I want to sort the names from the least to the high')
sortedWords = sort(words)
You get:
words =
1×12 cell array
'I' 'want' 'to' 'sort' 'the' 'names' 'from' 'the' 'least' 'to' 'the' 'high'
sortedWords =
1×12 cell array
'I' 'from' 'high' 'least' 'names' 'sort' 'the' 'the' 'the' 'to' 'to' 'want'
Categories
Find more on Resizing and Reshaping Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!