Path: news.mathworks.com!not-for-mail
From: "Guan Hong " <jail_mage86@hotmail.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Error Message "Subscripted assignment dimension mismatch"
Date: Mon, 26 Mar 2012 08:44:12 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 24
Message-ID: <jkpa8s$5dq$1@newscl01ah.mathworks.com>
References: <jkh52e$ko5$1@newscl01ah.mathworks.com> <jkighi$e6a$1@newscl01ah.mathworks.com>
Reply-To: "Guan Hong " <jail_mage86@hotmail.com>
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 1332751452 5562 172.30.248.38 (26 Mar 2012 08:44:12 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Mon, 26 Mar 2012 08:44:12 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 3397223
Xref: news.mathworks.com comp.soft-sys.matlab:762192

"Roger Stafford" wrote in message <jkighi$e6a$1@newscl01ah.mathworks.com>...
> "Guan Hong " <jail_mage86@hotmail.com> wrote in message <jkh52e$ko5$1@newscl01ah.mathworks.com>...
> > Hi, I have encountered an error message "Subscripted assignment dimension mismatch" while running the m-file below. I would like to seek your expertise as I am new to MatLab. Your help will be greatly appreciated.
> > ......
> >     if delta(:,t-1)>=1e-6
> >......
> > final_weight=weight(:,length(weight))
> > ......
> - - - - - - - - - -
>   One cause of trouble would likely be with the line:
> 
>  final_weight=weight(:,length(weight))
> 
> If you arrive there with the number of columns in 'weight' less than 10, the quantity "length(weight)" will nevertheless be equal to 10 and that will produce an error message.  You shouldn't use 'length' there, use 'size(weight,2)' (or better still use 'end'.).
> 
>   That may not be your only difficulty, though.  In the 'if' statement you have:
> 
>  delta(:,t-1)>=1e-6
> 
> My guess is that you want this to be considered true if any of the elements in delta(:,t-1) are greater than or equal to 1e-6.  However matlab will only regard it as true if all of them are greater than or equal to 1e-6.  That could cause you to do a 'break' prematurely.  You need to use the 'any' function in that case.
> 
> Roger Stafford

Thank you Roger Stafford for the advice. I've solved the error. Really appreciate your help. =)