Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
ending a script

Subject: ending a script

From: Jonathan

Date: 16 Sep, 2010 16:07:07

Message: 1 of 3

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

Subject: ending a script

From: Sean

Date: 16 Sep, 2010 16:17:19

Message: 2 of 3

"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

Subject: ending a script

From: Jonathan

Date: 16 Sep, 2010 16:32:21

Message: 3 of 3

"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.

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us