Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: TRANSLATE ONE VARIABLE INTO TWO
Date: Tue, 17 Apr 2012 14:52:07 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 57
Message-ID: <jmk02n$8ba$1@newscl01ah.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: www-06-blr.mathworks.com
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: newscl01ah.mathworks.com 1334674327 8554 172.30.248.38 (17 Apr 2012 14:52:07 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Tue, 17 Apr 2012 14:52:07 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 3397429
Xref: news.mathworks.com comp.soft-sys.matlab:764859

Hello!

Let assume that we have only 2 kinds of integer numbers input data: 2 and 4:

a = [
2
2
2
2
4
4
4
2
4
.
.
.
n]; 

and I want to create from it sth like that:
d = [
0 0
0 0 
0 0 
0 0 
1 1
1 1
1 1
0 0
1 1
.
.
.
n]; 

I want to translate n rows of data. 

if one value in vector a = 2, i want it to be 0 0, and if another value equals 4 to be 1 1. I know how to do it but I don't know how to write a code.

%=================
a = [2;4;2;242;2;4;4;4;4;2];
[a b] = size(a)
i = 1;
for i <b
if b(i)=2
d = [what?] 
else
d = [what?] 
end
i = i + 1;
end
d
%=================

How to create the output vector that will save in correct order the data from vector a?

Thanks for help!