A(B)=[] in anonymous function
8 次查看(过去 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!