Filter löschen
Filter löschen

The following error occurred converting from cell to double:

2 Ansichten (letzte 30 Tage)
Lee
Lee am 1 Mai 2013
hi i am very new to matlab so this might sound stupid to the experts so i appoligize
i need to create a function the gets a cell of words and a number and returns a new cell only containing word equal or longer to the number for exaample ({'is','a','sentence'},2)should come out is sentence now this is what i did
function newWordsList=eraseShortWords(worldlist,n)
counter=0;
%get the number of words
k=length(worldlist);
chosen=zeros(1,k);
for i=1:k
l=length(cell2mat(worldlist(1,i)));
if l>~n
counter=counter+1;
chosen(i)=worldlist(i);
end
newWordsList=chosen;
end
i keep getting error eraseShortWords({'add','dddd'},3) The following error occurred converting from cell to double: Error using double Conversion to double from cell is not possibl

Antworten (1)

Walter Roberson
Walter Roberson am 1 Mai 2013
You initialize chosen=zeros(1,k) so chosen is numeric. But you have
chosen(i)=wordlist(i)
and wordlist(i) is a cell array. You cannot store a cell array into a numeric location.
Likely fix:
chosen = cell(1,k);

Kategorien

Mehr zu Data Type Conversion finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by