0

I have a matrix <1x1000> containing integers. It contain the value 150 a couple of times and I want to remove that value completely. Any ideas how to?

Help is much appreciated!

J.Smith
  • 335
  • 1
  • 3
  • 8

2 Answers2

1

If you want to remove all elements that equal 150 then

M = M(M ~= 150)

If you want to remove all elements belonging to a list of undesired numbers then

list = [150, 230, 420]
M = M(~ismember(M, list))
Dan
  • 45,079
  • 17
  • 88
  • 157
0

Same but different expression

M(M==150)=[];

list = [150,230,420];
M(ismember(M,list))=[];

When you type A(index)=[], it delete A(index). For example,

A = [1,2,3];
A(2) = [];

Then

A = [1,3]
Dohyun
  • 642
  • 4
  • 15
  • It's slower to do it this way (http://stackoverflow.com/questions/12421345/deleting-matrix-elements-by-vs-reassigning-matrix) – Dan Jul 18 '16 at 10:27