New to Matlab- Pls help

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.


Comments

  • 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.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion