Matlab

Moderators: None (Apply to moderate this forum)
Number of threads: 1467
Number of posts: 2144

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
New to Matlab- Pls help Posted by anu914 on 16 May 2011 at 9:26 PM
Hi,

This is my first thread in this forum. Hope somebody will help me.

I am writing a simple Matlab program and in that I have an array of numbers with repeating numbers. I want to extract the dissimilar numbers and put in an array. I used below method to do that and it seems to work.


a=1;

for k=1:(2^n-1)

if Logpp(k)~= Logpp(k+1)
Logpp_val(a,1)=Logpp(k,1);
a=a+1;
k=k+1;

else
k=k+1;

end

end

Here I compare the numbers in the original array if they are not equal I write that to the final array.

I'd like to know whether there's an easier or rather optimized way to do this Matlab as I need to repeat this often in the program.

Thanks in advance for the help.


Report
Re: New to Matlab- Pls help Posted by jjasso5 on 17 May 2011 at 10:54 PM
You can use function "unique".

B = unique(A) for the array A returns the same
values as in A but with no repetitions. B will
also be sorted.

Type
help unique
on your command window to see the full description.



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.