A(B)=[] in anonymous function
2 ビュー (過去 30 日間)
古いコメントを表示
A=randi(100,1,100);
A(randi(100,1,10))=[];
The above code works well but how to write it in an anonymous function.
delete_ele=@(X,Y) X(Y)=[]
It throws the error,
delete_ele=@(X,Y) X(Y)=[]
↑
Error: The expression to the left of the equals sign is not
a valid target for an assignment.
How to resolve this issue.
0 件のコメント
採用された回答
Stephen23
2018 年 8 月 21 日
編集済み: Stephen23
2018 年 8 月 21 日
"A(B)=[] in anonymous function"
This is not possible: anonymous function do not allow allocations. But you can use indexing:
delete_ele = @(X,Y) X(~ismember(1:numel(X),Y));
Tested:
>> A = randi(100,1,100);
>> B = randi(100,1,10);
>> C = delete_ele(A,B);
>> size(C)
ans =
1 90
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Calculus についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!