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!