Cannot perform null assignment from variable
1 回表示 (過去 30 日間)
古いコメントを表示
The following code "works" (deletes the 3rd element of A, or the third page, if the first two dimensions are not 1 & 1):
A = nan(1,1,3);
A(3) = [];
This modification breaks the functionality and throws an error: "Unable to perform assignment because the size of the left side is 1-by-1 and the size of the right side is 0-by-0."
A = nan(1,1,3);
empty_scalar = [];
A(3) = empty_scalar;
I don't understand what's going on here -- why can't I do the same null assignment from a variable? Is "= []" special syntax?
I'd like to be able to automate the process of either assigning or deleting elements/columns/pages of some arbitrarily-sized array. How can I do this, given the above behavior?
Thanks.
1 件のコメント
Dyuman Joshi
2023 年 11 月 13 日
The first one is deletion.
The second one is assignment (as the error states as well).
採用された回答
その他の回答 (1 件)
Matt J
2023 年 11 月 13 日
Another workaround is to call subsasgn direclty,
A = nan(1,3);
empty_scalar = 4;
A=subsasgn(A, struct('type','()','subs',{{3}}) , empty_scalar)
empty_scalar = [];
A=subsasgn(A, struct('type','()','subs',{{3}}) , empty_scalar)
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!