ending a script

  • Follow


Hi,
I was wondering if someone could help me out with a minor problem.  I have the following portion of a much larger script (see below). My problem occurs when I enter a 1,8, or 9, which correctly runs another script.  The issue arises when the other script ends, and it reverts back to the script below and then continues with this main script.  How do I get it to simply stop running once it completes the seperate script for the values 1, 8, or 9? I thought by using the 'return' it would do that particular job, but not the case.

i = input('Enter the profile name for analyses > ');
if i==1
    run Newport_PlotEDA_pr1
    return
elseif i==8
    run Newport_PlotEDA_pr8
    return
elseif i==9
    run Newport_PlotEDA_pr9
    return
end
fname=sprintf('newport%d_EDA-B.txt',i);
cd ('C:\DATA\DOGAMI_projects\OBSMAP\Beach_profiles\Newport\EDA')
EDA = csvread(fname);            %load excursion distance data
ddate = load('newport_EDA_time.txt');       %load time data
yy = ddate(:,1);
mm = ddate(:,2);
dd = ddate(:,3);
time = datenum(yy,mm,dd);        %convert time data to matlab format


Many thanks
Jon
0
Reply Jonathan 9/16/2010 4:07:07 PM

"Jonathan" <jkakiwi@yahoo.co.uk> wrote in message <i6tfbb$d31$1@fred.mathworks.com>...
> Hi,
> I was wondering if someone could help me out with a minor problem.  I have the following portion of a much larger script (see below). My problem occurs when I enter a 1,8, or 9, which correctly runs another script.  The issue arises when the other script ends, and it reverts back to the script below and then continues with this main script.  How do I get it to simply stop running once it completes the seperate script for the values 1, 8, or 9? I thought by using the 'return' it would do that particular job, but not the case.
> 
> i = input('Enter the profile name for analyses > ');
> if i==1
>     run Newport_PlotEDA_pr1
>     return
> elseif i==8
>     run Newport_PlotEDA_pr8
>     return
> elseif i==9
>     run Newport_PlotEDA_pr9
>     return
> end
> fname=sprintf('newport%d_EDA-B.txt',i);
> cd ('C:\DATA\DOGAMI_projects\OBSMAP\Beach_profiles\Newport\EDA')
> EDA = csvread(fname);            %load excursion distance data
> ddate = load('newport_EDA_time.txt');       %load time data
> yy = ddate(:,1);
> mm = ddate(:,2);
> dd = ddate(:,3);
> time = datenum(yy,mm,dd);        %convert time data to matlab format
> 
> 
> Many thanks
> Jon

You could put all of the statements after the end into a non-conditional else statement so that once the program is done (w/ 1 8 9) nothing else is called.  I.e:

> i = input('Enter the profile name for analyses > ');
> if i==1
>     run Newport_PlotEDA_pr1
>     return
> elseif i==8
>     run Newport_PlotEDA_pr8
>     return
> elseif i==9
>     run Newport_PlotEDA_pr9
>     return
else
> fname=sprintf('newport%d_EDA-B.txt',i);
> cd ('C:\DATA\DOGAMI_projects\OBSMAP\Beach_profiles\Newport\EDA')
> EDA = csvread(fname);            %load excursion distance data
> ddate = load('newport_EDA_time.txt');       %load time data
> yy = ddate(:,1);
> mm = ddate(:,2);
> dd = ddate(:,3);
> time = datenum(yy,mm,dd);        %convert time data to matlab format
end
0
Reply Sean 9/16/2010 4:17:19 PM


"Sean " <sean.dewolski@nospamplease.umit.maine.edu> wrote in message <i6tfuf$m9d$1@fred.mathworks.com>...
> "Jonathan" <jkakiwi@yahoo.co.uk> wrote in message <i6tfbb$d31$1@fred.mathworks.com>...
> > Hi,
> > I was wondering if someone could help me out with a minor problem.  I have the following portion of a much larger script (see below). My problem occurs when I enter a 1,8, or 9, which correctly runs another script.  The issue arises when the other script ends, and it reverts back to the script below and then continues with this main script.  How do I get it to simply stop running once it completes the seperate script for the values 1, 8, or 9? I thought by using the 'return' it would do that particular job, but not the case.
> > 
> > i = input('Enter the profile name for analyses > ');
> > if i==1
> >     run Newport_PlotEDA_pr1
> >     return
> > elseif i==8
> >     run Newport_PlotEDA_pr8
> >     return
> > elseif i==9
> >     run Newport_PlotEDA_pr9
> >     return
> > end
> > fname=sprintf('newport%d_EDA-B.txt',i);
> > cd ('C:\DATA\DOGAMI_projects\OBSMAP\Beach_profiles\Newport\EDA')
> > EDA = csvread(fname);            %load excursion distance data
> > ddate = load('newport_EDA_time.txt');       %load time data
> > yy = ddate(:,1);
> > mm = ddate(:,2);
> > dd = ddate(:,3);
> > time = datenum(yy,mm,dd);        %convert time data to matlab format
> > 
> > 
> > Many thanks
> > Jon
> 
> You could put all of the statements after the end into a non-conditional else statement so that once the program is done (w/ 1 8 9) nothing else is called.  I.e:
> 
> > i = input('Enter the profile name for analyses > ');
> > if i==1
> >     run Newport_PlotEDA_pr1
> >     return
> > elseif i==8
> >     run Newport_PlotEDA_pr8
> >     return
> > elseif i==9
> >     run Newport_PlotEDA_pr9
> >     return
> else
> > fname=sprintf('newport%d_EDA-B.txt',i);
> > cd ('C:\DATA\DOGAMI_projects\OBSMAP\Beach_profiles\Newport\EDA')
> > EDA = csvread(fname);            %load excursion distance data
> > ddate = load('newport_EDA_time.txt');       %load time data
> > yy = ddate(:,1);
> > mm = ddate(:,2);
> > dd = ddate(:,3);
> > time = datenum(yy,mm,dd);        %convert time data to matlab format
> end

Thanks Sean, this worked. 
0
Reply Jonathan 9/16/2010 4:32:21 PM

2 Replies
358 Views

(page loaded in 1.442 seconds)

Similiar Articles:













7/22/2012 3:00:15 AM


Reply: