New Reply

Deleting an entry from an array in MATLAB

 
Share Thread Thread Tools
Jul16-12, 05:06 PM   #1
 

Deleting an entry from an array in MATLAB


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]?
PhysOrg.com
PhysOrg
science news on PhysOrg.com

>> Intel's Haswell to extend battery life, set for Taipei launch
>> Galaxies fed by funnels of fuel
>> The better to see you with: Scientists build record-setting metamaterial flat lens
Jul17-12, 08:01 PM   #2
 
Blog Entries: 1
Recognitions:
Gold Membership Gold Member
Homework Helper Homework Help
Science Advisor Science Advisor
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.
Jul25-12, 12:50 PM   #3
 
Thanks!!
Jul25-12, 02:00 PM   #4
 
Recognitions:
Science Advisor Science Advisor

Deleting an entry from an array in MATLAB


Or even just A( A==4) = [] will work.
New Reply
Thread Tools


Similar Threads for: Deleting an entry from an array in MATLAB
Thread Forum Replies
Matlab: how to use an array in a matrix Math & Science Software 5
MATLAB Multidimensional Array Math & Science Software 3
MATLAB: deleting rows Programming & Comp Sci 1
Matlab char array help please? Math & Science Software 2