The following error occurred converting from cell to double:
조회 수: 1 (최근 30일)
이전 댓글 표시
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
댓글 수: 0
답변 (1개)
Walter Roberson
2013년 5월 1일
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);
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Data Type Conversion에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!