A(B)=[] in anonymous function

조회 수: 2 (최근 30일)
ANKUR KUMAR
ANKUR KUMAR 2018년 8월 21일
편집: Stephen23 2018년 8월 21일
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.

채택된 답변

Stephen23
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
  댓글 수: 1
ANKUR KUMAR
ANKUR KUMAR 2018년 8월 21일
Thanks for your response.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Calculus에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by