Conversion to cell from char is not possible
Show older comments
I'm writing a script that will read a set of names from a spreadsheet, make all letters in the names lowercase, capitalize the first letter of each new name, and move the first name to the end of the string, then write the new set of names to the spreadsheet. So, for example, GLENN CURTISS T & MYRA B becomes Curtiss T & Myra B Glenn.
[nothing, names] = xlsread(filepath, sheet, range);
names = lower(names);
for i = 1:length(names)
stringWords = strread(names{i}, '%s'); %create an array of each "word" in a name
for j = 1:length(stringWords)
charWords = char(stringWords{j}); %for each word, convert it into a character array
charWords(1) = upper(charWords(1)); %capitalize the first letter of the working word
stringWords{j} = cellstr(charWords); %write edited string back to stringWords
end
% rest of the program
%
%
end
This gives me an error saying "Conversion to cell from char is not possible." My understanding of this code is that charWords is a char array identical to the string stored in cell j of stringWords. After capitalizing the first letter, cellstr(charWords) should convert the string made up by charWords into a cell that can be returned to stringWords. What am I doing wrong?
5 Comments
Josh G
on 14 Jul 2015
the cyclist
on 14 Jul 2015
The complete error message would include the line number, etc.
Even better would be for you to put in an example of nothing and names that reproduces the error, so that we have a self-contained code snippet that we can run.
It is possible that the error message only contains that one line, as this demonstrates:
>> A = {3}; % note: a cell array!
>> A(1) = 'b'
Conversion to cell from char is not possible.
but this can only happen at the command line. Whereas in a script or function, e.g.:
for k = 1:3
A = {k}; % cell!
A(k) = 'b';
end
the error message will always give the Mfile name, the line number and also quotes the code where the problem is detected:
>> Untitled
Conversion to cell from char is not possible.
Error in Untitled (line 4)
A(k) = 'b';
Accepted Answer
More Answers (1)
Image Analyst
on 14 Jul 2015
0 votes
I think you will understand after you read the FAQ, which gives a good intuitive description of cells and when to use braces or parentheses. http://matlab.wikia.com/wiki/FAQ#What_is_a_cell_array.3F
Categories
Find more on Environment and Settings 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!