필터 지우기
필터 지우기

How made the code as easy?

조회 수: 2 (최근 30일)
VIJAY
VIJAY 2018년 11월 8일
편집: madhan ravi 2018년 11월 8일
P=[1 32 3 78 5 6 7 8 9 10] ;P is my original array which has the size is 1*10; I have Q=[2 4 7];I want delete in Q array value in P array; My expect output is P=[ 1 3 5 6 8 9 10] by using for loop only because of the size of Q array may be change ;P(:,[Q(1) Q(2) Q(3)])=[] this command use only the size of Q array is 1*3 .So I need for loop logic which is common of any array size.

채택된 답변

madhan ravi
madhan ravi 2018년 11월 8일
편집: madhan ravi 2018년 11월 8일
P(Q)=[] %edited after Jan's comment
  댓글 수: 13
Jan
Jan 2018년 11월 8일
You can omit the square brackets and 1:end :
P(Q)=[]
madhan ravi
madhan ravi 2018년 11월 8일
+1 @Jan cool

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

추가 답변 (1개)

Stephan
Stephan 2018년 11월 8일
편집: Stephan 2018년 11월 8일
If you want to delete the values at the indicies in P, that are specified in Q use the answer from Madhan above. If you need to delete the values in P specified in Q use:
P(ismember(P,Q))=[]
  댓글 수: 1
madhan ravi
madhan ravi 2018년 11월 8일
+1 another way of approach

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

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by