How made the code as easy?

1 次查看(过去 30 天)
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)=[]

请先登录,再进行评论。

更多回答(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))=[]

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by