Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: TRANSLATE ONE VARIABLE INTO TWO
Date: Tue, 17 Apr 2012 15:29:08 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 31
Message-ID: <jmk284$h2a$1@newscl01ah.mathworks.com>
References: <jmk02n$8ba$1@newscl01ah.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: www-00-blr.mathworks.com
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: newscl01ah.mathworks.com 1334676548 17482 172.30.248.45 (17 Apr 2012 15:29:08 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Tue, 17 Apr 2012 15:29:08 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1187260
Xref: news.mathworks.com comp.soft-sys.matlab:764863

"Slawomir" wrote in message <jmk02n$8ba$1@newscl01ah.mathworks.com>...
> 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 about

 d = [a/2-1,a/2-];

  However if you wish to use a for-loop and the if-else construct, it would be something like this:

 for k = 1:size(a,1)
  if a(k) == 2
   d(k,:) = [0,0];
  else
   d(k,:) = [1,1];
  end
 end

  I would advise you to read the pertinent documentation on this carefully.  The for-loop index should not be altered as you have done with "i=i+1" since that is automatically done.  Also "b(i)=2" is not correct.  Use "==" for equality tests.

Roger Stafford