I am getting error "Cell contents reference from a non-cell array object" . Please tell me how to solve this problem.
Cell contents reference from a non-cell array object.
조회 수: 1 (최근 30일)
이전 댓글 표시
marcos flavio paula miranda junior
2020년 11월 22일
댓글: marcos flavio paula miranda junior
2020년 11월 22일
clc;
clear all;
vchave = [2 2 2 2 2 2]
for k = 1:6;
v{k} = vchave
v{1,k} = v{1,k}-1
v{1}{k+1} = v{1}{k+1}-1
end
I am getting error "Cell contents reference from a non-cell array object" . Please tell me how to solve this problem.
채택된 답변
Stephen23
2020년 11월 22일
편집: Stephen23
2020년 11월 22일
Each cell of v contains a numeric vector. So your indexing here:
v{1}{k+1} = v{1}{k+1}-1
% ^ ^ ^ ^ wrong type of bracekts for numeric array.
uses the wrtong type of brackets for indexing (curly braces are used to access the elements of a container array, e.g. the elements of a cell array, table, or string). The correct brackets for accessing the elements of a numeric array are parentheses, as shown here:
vchave = [2,2,2,2,2,2];
for k = 1:5;
v{k} = vchave
v{1,k} = v{1,k}-1
v{1}(k+1) = v{1}(k+1)-1
end
I strongly recommend preallocating v before the loop.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!