Why I'm getting AAAA... when using char??

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 Kommentare

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.
@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?

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Image Analyst
Image Analyst am 30 Aug. 2017

1 Stimme

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'

Kategorien

Tags

Gefragt:

am 30 Aug. 2017

Kommentiert:

Jan
am 30 Aug. 2017

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by