Error: Unable to perform assignment because brace indexing is not supported for variables of this type

1 回表示 (過去 30 日間)
Hi everybody,
if I launch this code using a single POINT it works, if instead I insert it inside a loop (with POINT that change at every iteration) this message error appears to me:
Unable to perform assignment because brace indexing is not supported for variables of this type
POINT=[x,y,z]
nRow = size(A, 1);
for iRow = 1:nRow
STRAIGHT=-20:.01:20;
STRGT{iRow}=repmat(POINT,length(STRAIGHT),1)'+((A(iRow,:))-POINT)'*STRAIGHT;
end
How can i resolve it?
Thank's!
  2 件のコメント
madhan ravi
madhan ravi 2019 年 1 月 31 日
編集済み: madhan ravi 2019 年 1 月 31 日
STRGT=cell(1,nRow); % before loop , also move STRAIGHT outside the loop
[comment moved to answer section]

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

採用された回答

madhan ravi
madhan ravi 2019 年 1 月 31 日
STRGT=cell(1,nRow); % before the loop ,also move STRAIGHT outside the loop
  2 件のコメント
Muhammad Usman Saleem
Muhammad Usman Saleem 2022 年 10 月 29 日
Why its necessary to declar an empty cell array before loop?
Why Matlab through this error when we try to declar inside loop? please
Stephen23
Stephen23 2022 年 10 月 29 日
"Why its necessary to declar an empty cell array before loop? "
It is not empty, it has size 1xnRow.
The reason is to preallocate the array before the loop, thus specifying both the size and type of the array:

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

その他の回答 (1 件)

KSSV
KSSV 2019 年 1 月 31 日
編集済み: KSSV 2019 年 1 月 31 日
POINT=[x,y,z] ;
nRow = size(A, 1);
STRGT = cell(nRow,1) ;
for iRow = 1:nRow
STRAIGHT=-20:.01:20;
STRGT{iRow}=repmat(POINT,length(RETTA),1)'+((A(iRow,:))-POINT)'*STRAIGHT;
end

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by