Deleting an entry from an array in MATLAB

  • Thread starter Thread starter math8
  • Start date Start date
  • Tags Tags
    Array Matlab
math8
Messages
143
Reaction score
0
I want a code in MATLAB that produces A\{4}, where A={3,6,1,-3,4,8}.

I know for instance:
A=[ 3 6 1 -3 4 8];

A(5)=[]; produces

3 6 1 -3 8

But what should I do if I don't know the index (in this case 5) for the entry '4'; and I want to get
[ 3 6 1 -3 8]?
 
Physics news on Phys.org
You could try something like

idx = find(A == 4);
A(idx) = [];

This will remove all instances of 4 from the array. If the array doesn't contain any 4's, then nothing will be removed.
 
Thanks!
 
Or even just A( A==4) = [] will work.
 
Prove $$\int\limits_0^{\sqrt2/4}\frac{1}{\sqrt{x-x^2}}\arcsin\sqrt{\frac{(x-1)\left(x-1+x\sqrt{9-16x}\right)}{1-2x}} \, \mathrm dx = \frac{\pi^2}{8}.$$ Let $$I = \int\limits_0^{\sqrt 2 / 4}\frac{1}{\sqrt{x-x^2}}\arcsin\sqrt{\frac{(x-1)\left(x-1+x\sqrt{9-16x}\right)}{1-2x}} \, \mathrm dx. \tag{1}$$ The representation integral of ##\arcsin## is $$\arcsin u = \int\limits_{0}^{1} \frac{\mathrm dt}{\sqrt{1-t^2}}, \qquad 0 \leqslant u \leqslant 1.$$ Plugging identity above into ##(1)## with ##u...
Back
Top