Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Removing rows containing all zeros in a matrix
Date: Tue, 13 Jul 2010 19:06:19 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 20
Message-ID: <i1idfb$mgq$1@fred.mathworks.com>
References: <hs1pti$hmk$1@fred.mathworks.com> <hs1qg9$psa$1@fred.mathworks.com> <i1iaj1$d8k$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-03-blr.mathworks.com
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1279047979 23066 172.30.248.38 (13 Jul 2010 19:06:19 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Tue, 13 Jul 2010 19:06:19 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1895050
Xref: news.mathworks.com comp.soft-sys.matlab:652802

"Anthony Hopf" <anthony.hopf@gmail.com> wrote in message <i1iaj1$d8k$1@fred.mathworks.com>...
> But what if you want to replace the values?
> 
> m(any(m ==0,2),:)=[1 1 1];
> 
> This doesn't work, I get a dimension mismatch problem.
> 
> Thank you


m=[
  1 2 3
  0 4 5
  0 0 0
  6 0 0
];
n = any(m==0,2);
m(n,:)=repmat([1 1 1],[sum(n) 1]);

You got dimension mismatch because you were trying to assign a 1x3 array to a 3x3 array.  You need to ensure the data you're inserting is the same size as the data you're editing.