Cell contents reference from a non-cell array object.

1 回表示 (過去 30 日間)
marcos flavio paula miranda junior
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.
  1 件のコメント
marcos flavio paula miranda junior
marcos flavio paula miranda junior 2020 年 11 月 22 日
I am getting error "Cell contents reference from a non-cell array object" . Please tell me how to solve this problem.

サインインしてコメントする。

採用された回答

Stephen23
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
v = 1x1 cell array
{1×6 double}
v = 1x1 cell array
{1×6 double}
v = 1x1 cell array
{1×6 double}
v = 1x2 cell array
{1×6 double} {1×6 double}
v = 1x2 cell array
{1×6 double} {1×6 double}
v = 1x2 cell array
{1×6 double} {1×6 double}
v = 1x3 cell array
{1×6 double} {1×6 double} {1×6 double}
v = 1x3 cell array
{1×6 double} {1×6 double} {1×6 double}
v = 1x3 cell array
{1×6 double} {1×6 double} {1×6 double}
v = 1x4 cell array
{1×6 double} {1×6 double} {1×6 double} {1×6 double}
v = 1x4 cell array
{1×6 double} {1×6 double} {1×6 double} {1×6 double}
v = 1x4 cell array
{1×6 double} {1×6 double} {1×6 double} {1×6 double}
v = 1x5 cell array
{1×6 double} {1×6 double} {1×6 double} {1×6 double} {1×6 double}
v = 1x5 cell array
{1×6 double} {1×6 double} {1×6 double} {1×6 double} {1×6 double}
v = 1x5 cell array
{1×6 double} {1×6 double} {1×6 double} {1×6 double} {1×6 double}
I strongly recommend preallocating v before the loop.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLabels and Styling についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by