Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Numeric Comparison

Subject: Numeric Comparison

From: Jawad

Date: 14 Nov, 2011 00:16:10

Message: 1 of 2

I have one matrix called targets (1X4000); column 1 to 2000 contains double value 0 and column 2001 to 4000 contains double value 1

a)
i want to create a matrix called targets_1 where i want to check if the value is 0 then make the entry 1 so at the end of the day i must have a matrix with :column 1 to 2000 with value 1 and column 2001:4000 with value zero

b)
Same situation as above but this time i want to check if the value is 1 then make the entry 1 and if it is zero then make the entry zero; at the end; my new matrix targets_2 contains values: column 1 to 2000 with value zero and column 2001:4000 with value 1

i know how to use the strcmp function to make such checking with strings, but problem is that my original matrix is double and i dont know if there is such function like

setosaCmp = strcmp('setosa',species);

which could work with double (numbers); any help would be appreciated

Subject: Numeric Comparison

From: Claudio

Date: 14 Nov, 2011 12:12:10

Message: 2 of 2

Hi Jawad,

I think this might do the trick:

targets = [zeros(1,2000) ones(1,2000)];
targets_1 = targets == 0;
targets_2 = targets == 1;


targets_1 and targets_2 will be "logical"; if you want double:
targets_1 = double(targets == 0);
targets_2 = double(targets == 1);

Good luck!
Claudio




"Jawad " <jawadhasan80@gmail.com> wrote in message <j9pmka$48q$1@newscl01ah.mathworks.com>...
> I have one matrix called targets (1X4000); column 1 to 2000 contains double value 0 and column 2001 to 4000 contains double value 1
>
> a)
> i want to create a matrix called targets_1 where i want to check if the value is 0 then make the entry 1 so at the end of the day i must have a matrix with :column 1 to 2000 with value 1 and column 2001:4000 with value zero
>
> b)
> Same situation as above but this time i want to check if the value is 1 then make the entry 1 and if it is zero then make the entry zero; at the end; my new matrix targets_2 contains values: column 1 to 2000 with value zero and column 2001:4000 with value 1
>
> i know how to use the strcmp function to make such checking with strings, but problem is that my original matrix is double and i dont know if there is such function like
>
> setosaCmp = strcmp('setosa',species);
>
> which could work with double (numbers); any help would be appreciated

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us