Borrar filtros
Borrar filtros

The following error occurred converting from cell to double:

1 visualización (últimos 30 días)
Lee
Lee el 1 de Mayo de 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

Respuestas (1)

Walter Roberson
Walter Roberson el 1 de Mayo de 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);

Categorías

Más información sobre Data Type Conversion en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by