"someone " <someone@somewhere.net> wrote in message
<f9flfi$t5f$1@fred.mathworks.com>...
> "huda nawaf" <halmamory@yahoo.com> wrote in message
> <f9f08u$qqp$1@fred.mathworks.com>...
> > how I can use go to statment in matlab?
>
>
> See:
>
> <http://blogs.mathworks.com/loren/2006/04/01/goto-coming-
at-
> long-last-vectorized-no-less/>
>
>
hi someone,
I cant access to this web.
if you have another please give it.
thanks,huda
roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson) wrote in
message <f9fm8n$7g1$1@canopus.cc.umanitoba.ca>...
> In article <f9f180$f8j$1@fred.mathworks.com>, us
<us@neurol.unizh.ch> wrote:
> >huda nawaf:
> ><SNIP stubborn...
>
> >> how I can use go to statment in matlab?
>
> >the <goto> statement does not exist in ML...
>
> *Some* uses of goto can be replaced by try/catch blocks
> catching custom error() conditions.
> --
> Prototypes are supertypes of their clones. --
maplesoft
hi us,
please I don't know how can use it (try and catch)
please give me example .
thanks
In article <fa61hd$so$1@fred.mathworks.com>,
huda nawaf <halmamory@yahoo.com> wrote:
>roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson) wrote in
>message <f9fm8n$7g1$1@canopus.cc.umanitoba.ca>...
>> In article <f9f180$f8j$1@fred.mathworks.com>, us
><us@neurol.unizh.ch> wrote:
>> >huda nawaf:
>> ><SNIP stubborn...
>> >> how I can use go to statment in matlab?
>> >the <goto> statement does not exist in ML...
>> *Some* uses of goto can be replaced by try/catch blocks
>> catching custom error() conditions.
>hi us,
'us' was the person who mentioned that goto does not exist.
The person you are replying to, who mentioned try and catch,
is 'Walter'.
>please I don't know how can use it (try and catch)
>please give me example .
%code as it would be if GO TO existed:
for K = 1:N
do_something;
if some_variable == 0, GO TO Opps0, end;
do_something_more;
end
return
Opps0:
sprintf('Zero encountered at iteration %d\n', K);
return
%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
--
"No one has the right to destroy another person's belief by
demanding empirical evidence." -- Ann Landers
roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson) wrote in
message <fa64gs$d9m$1@canopus.cc.umanitoba.ca>...
> In article <fa61hd$so$1@fred.mathworks.com>,
> huda nawaf <halmamory@yahoo.com> wrote:
> >roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson) wrote in
> >message <f9fm8n$7g1$1@canopus.cc.umanitoba.ca>...
> >> In article <f9f180$f8j$1@fred.mathworks.com>, us
> ><us@neurol.unizh.ch> wrote:
> >> >huda nawaf:
> >> ><SNIP stubborn...
>
> >> >> how I can use go to statment in matlab?
>
> >> >the <goto> statement does not exist in ML...
>
> >> *Some* uses of goto can be replaced by try/catch
blocks
> >> catching custom error() conditions.
>
> >hi us,
>
> 'us' was the person who mentioned that goto does not
exist.
> The person you are replying to, who mentioned try and
catch,
> is 'Walter'.
>
> >please I don't know how can use it (try and catch)
> >please give me example .
>
>
> %code as it would be if GO TO existed:
> for K = 1:N
> do_something;
> if some_variable == 0, GO TO Opps0, end;
> do_something_more;
> end
> return
>
> Opps0:
> sprintf('Zero encountered at iteration %d\n', K);
> return
>
>
> %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
> --
> "No one has the right to destroy another person's
belief by
> demanding empirical evidence." -- Ann
Landers
hi Roberson,
thanks ,
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.
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.
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
> 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
>
>
I don't understand why this needs try/catch. How about this instead:
s=0;
for K =1:20
s=s+1;
if K == 20
break; % exit out of loop
end
%do_something_more;
g=10;
for i=1:10
s=s+g;
end
end
If you need to execute a cleanup condition, use an additional flag,
like
In article <fae87n$651$1@fred.mathworks.com>,
huda nawaf <halmamory@yahoo.com> wrote:
> 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'
if strcmp(lasterror.message,'Opps0')
>
> return
>
> rethrow(lasterror)
>end
>end
In my opinion, if you don't have enough programming skills to be able
to debug a minor problem such as that, then you absolutely
positively should not be using try/catch error processing.
I've been programming for 30 years. I think the last time that
I needed a GOTO construct was about 18 years ago, cleaning up
some Fortran code that had been under development by random students
for 20 years.
--
"No one has the right to destroy another person's belief by
demanding empirical evidence." -- Ann Landers
> I've been programming for 30 years. I think the last time
that
> I needed a GOTO construct was about 18 years ago,
cleaning up
> some Fortran code that had been under development by
random students
> for 20 years.
I know this is old, but I'm eagerly looking forwards to the
addition of GOTO to MatLab.
One simple reason: It's fast. Really fast. I work with
people who do real-time data collection using MatLab and
need to iterate through loops in the range of milliseconds
or less. GOTO's can really help when you need to pare your
code down to nothing!
In article <fq6nrs$kq0$1@fred.mathworks.com>,
James <kilrogg311@yahoo.com> wrote:
>> I've been programming for 30 years. I think the last time
>that
>> I needed a GOTO construct was about 18 years ago,
>cleaning up
>> some Fortran code that had been under development by
>random students
>> for 20 years.
>I know this is old, but I'm eagerly looking forwards to the
>addition of GOTO to MatLab.
>One simple reason: It's fast. Really fast. I work with
>people who do real-time data collection using MatLab and
>need to iterate through loops in the range of milliseconds
>or less. GOTO's can really help when you need to pare your
>code down to nothing!
a GOTO in MATLAB would not necessarily be very fast: it might have
to visit all of the statements in-between. You can see this effect
if you profile an if/else construct: even when the else clause
is never taken, the profiler will ascribe time to it.
--
"Is there any thing whereof it may be said, See, this is new? It hath
been already of old time, which was before us." -- Ecclesiastes
Public Submission Policy
NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for
all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content.
Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available
via MATLAB Central. Read the complete Disclaimer prior to use.