Path: news.mathworks.com!not-for-mail
From: "huda nawaf" <halmamory@yahoo.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: go to statment in matlab
Date: Tue, 21 Aug 2007 08:37:11 +0000 (UTC)
Organization: Babylon
Lines: 91
Message-ID: <fae87n$651$1@fred.mathworks.com>
References: <f9f08u$qqp$1@fred.mathworks.com> <fa61hd$so$1@fred.mathworks.com> <fa64gs$d9m$1@canopus.cc.umanitoba.ca> <fa6c94$70h$1@fred.mathworks.com> <fa77b3$3pt$1@canopus.cc.umanitoba.ca>
Reply-To: "huda nawaf" <halmamory@yahoo.com>
NNTP-Posting-Host: webapp-02-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1187685431 6305 172.30.248.37 (21 Aug 2007 08:37:11 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Tue, 21 Aug 2007 08:37:11 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1077087
Xref: news.mathworks.com comp.soft-sys.matlab:424745


roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson) wrote in 
message <fa77b3$3pt$1@canopus.cc.umanitoba.ca>...
> In article <fa6c94$70h$1@fred.mathworks.com>,
> huda nawaf <halmamory@yahoo.com> wrote:
> >roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson) wrote in 
> >message <fa64gs$d9m$1@canopus.cc.umanitoba.ca>...
> 
> >> %code using try/catch instead:
> >> try
> >>   for K =1:N
> >>     do_something;
> >>     if some_variable == 0 then error('Opps0') end;
> >>     do_something_more;
> >>   end
> >>   return
> >> catch
> >>   if lasterror == 'Opps0'
> >>     sprintf('Zero encountered at iteration %d\n', K);
> >>     return
> >>   else
> >>     rethrow(lasterror)
> >>   end
> >> end
> 
> >hi Roberson,
> 
> "Roberson" is my family name, not my personal name.
> 
> 
> >When I running this example . The following message 
error 
> >appeared:
> >??? Error: File: e:\MATLAB6p5\work\us.m Line: 4 Column: 
29
> >Missing operator, comma, or semicolon.
> 
> You weren't meant to literally run it! It was an 
outline, nothing more!!
> 
> But the problem was that I've been using other 
programming
> languages lately, so I accidently used 'then' instead of 
the Matlab
> equivilent structure:
> 
>   if some_variable == 0, error('Opps0'), end
> or
>   if some_variable == 0
>     error('Opps0')
>   end
> 
> -- 
> Programming is what happens while you're busy making 
other plans.
thank you very much my dear,
I very appreciate your help.
Really I need that. I tried execute your code:

 s=0;
 try for K =1:20

    s=s+1;
 if K == 20
    error('Opps0')
  end
  
 %do_something_more;
 g=10;
 for i=1:10
     s=s+g;
 
end
end
 return
catch
  if lasterror =='Opps0'

  return
  
 rethrow(lasterror)
end
end
but still there is aproblem .there are errors such:
??? Error using ==> ==
Function '==' is not defined for values of class 'struct'.

Error in ==> e:\MATLAB6p5\work\us1.m
On line 18  ==>   if lasterror =='Opps0'
thanks again