Convert letters to numbers in cell
Ältere Kommentare anzeigen
Hello,
I have a cell array that looks like :
{A, E, B, A, D, C; B, A, A, D, C, E}
for 9x28 cell
I want to replace A's with 5 for columns 1, 2, 4, 6, 8, 11, 14, 17, 19, 22, 23 ,24 ,26 27 and replace E's with 5 for columns 3, 5, 7, 9, 10, 12, 13, 15, 16, 18, 20, 21, 25, 28
so that for some columns, A-E ranges from 5-1 and for others A-E ranges from 1-5.
i have tried:
mydata = cell2mat(mydata);
mydata(mydata == 'A') = '1';
mydata(mydata == 'B') = '2';
mydata(mydata == 'C') = '3';
mydata(mydata == 'D') = '4';
mydata(mydata == 'E') = '5';
but this of course is not column specific. is there anyway i can isolate columns?
also, when i try to convert it back to a double with:
mydata= str2double(mydata) I get all NaN values
this does not work either:
y = sprintf('%s', mydata{:}):
x = sscanf(y,'%f');
i get the error: Expression or statement is incomplete or incorrect.
what can i do?
Thank you so much for your time and help!
1 Kommentar
Jan
am 16 Jul. 2012
I do not understand the question. It is not clear, when you are talking about numbers and when about characters. I do not know mydata and cannot run the code you have posted. Please clarify the question by editing it.
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Data Type Conversion finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!