Skip to Main Content Skip to Search
Login
File Exchange
MATLAB Newsgroup
Link Exchange
  Blogs  
 Contest 
MathWorks.com

Thread Subject: if-statement with several commands in true case

Subject: if-statement with several commands in true case

From: Corinna Schmitt

Date: 06 Aug, 2007 10:02:47

Message: 1 of 6

Hallo,

I want to work with the if-case. If a variable has a
special value than a block of commands should be done. My
idea was:

answer = input('Has your file this order? [Y/N] - ','s');

if answer=='Y' (
    numberOfRowsPlusHeader = str2num(input('How many rows
              inclusiv header has your input-file? ','s'));
    numberOfRowsPlusHeader;

    %verify by user: name of input
    source = input('Which file should be imported? ','s');
    source;

    %number and names of varaiables in [] brackets
    %correponds to the header of
    %the AIDA-output file (=column names)
    %number of %s corresponds to the number of column of
    %the AIDA-output file
    [MchipsID, prim_sec, Name, Integral, Bkg, category,
    Label, Area, Integral_Bkg, Homogeneity, Saturated,
    Quality] = ...
    textread(source,'%s %s %s %s %s %s %s %s %s %s %s %
    s',numberOfRowsPlusHeader, 'delimiter', '\t');
)
elseif
    display('Reorder you file and start the program again!')
end

I always receive the following error message:
??? Error: File: aidaimportV5.m Line: 80 Column: 17
Expression or statement is incorrect--possibly unbalanced
(, {, or [.

Can anyone help me?

Corinna

Subject: Re: if-statement with several commands in true case

From: John D'Errico

Date: 06 Aug, 2007 10:43:00

Message: 2 of 6

"Corinna Schmitt" <csc@mathworks.com> wrote in message
<f96rk7$flf$1@fred.mathworks.com>...
> Hallo,
>
> I want to work with the if-case. If a variable has a
> special value than a block of commands should be done. My
> idea was:
>
> answer = input('Has your file this order? [Y/N] - ','s');
>
> if answer=='Y' (

(snipped)

> )
> elseif
> display('Reorder you file and start the program again!')
> end
>
> I always receive the following error message:
> ??? Error: File: aidaimportV5.m Line: 80 Column: 17
> Expression or statement is incorrect--possibly unbalanced
> (, {, or [.
>
> Can anyone help me?

I don't remember anywhere in the Matlab
documentation where it says to use ( ) to
wrap an if case.

In fact, I wonder if it is even legal matlab
syntax. It might be legal syntax in some
other language, but Matlab is not some
other language.

John

Subject: Re: if-statement with several commands in true case

From: us

Date: 06 Aug, 2007 11:31:51

Message: 3 of 6

John D'Errico:
<SNIP unrelated OP...

> It might be legal syntax in some
> other language, but Matlab is not some
> other language...

not at all, in fact, ML is a lifestyle...

us

Subject: Re: if-statement with several commands in true case

From: John D'Errico

Date: 06 Aug, 2007 12:57:56

Message: 4 of 6

"us " <us@neurol.unizh.ch> wrote in message
<f970r7$j83$1@fred.mathworks.com>...
> John D'Errico:
> <SNIP unrelated OP...
>
> > It might be legal syntax in some
> > other language, but Matlab is not some
> > other language...
>
> not at all, in fact, ML is a lifestyle...
>
> us

Or sometimes a religion. ;-)

John

Subject: Re: if-statement with several commands in true case

From: John D'Errico

Date: 06 Aug, 2007 12:57:58

Message: 5 of 6

"us " <us@neurol.unizh.ch> wrote in message
<f970r7$j83$1@fred.mathworks.com>...
> John D'Errico:
> <SNIP unrelated OP...
>
> > It might be legal syntax in some
> > other language, but Matlab is not some
> > other language...
>
> not at all, in fact, ML is a lifestyle...
>
> us

Or sometimes a religion. ;-)

John

Subject: Re: if-statement with several commands in true case

From: DanK

Date: 06 Aug, 2007 14:24:36

Message: 6 of 6

On Aug 6, 6:02 am, "Corinna Schmitt" <c...@mathworks.com> wrote:
> Hallo,
>
> I want to work with the if-case. If a variable has a
> special value than a block of commands should be done. My
> idea was:
>
> answer = input('Has your file this order? [Y/N] - ','s');
>
> if answer=='Y' (
> numberOfRowsPlusHeader = str2num(input('How many rows
> inclusiv header has your input-file? ','s'));
> numberOfRowsPlusHeader;
>
> %verify by user: name of input
> source = input('Which file should be imported? ','s');
> source;
>
> %number and names of varaiables in [] brackets
> %correponds to the header of
> %the AIDA-output file (=column names)
> %number of %s corresponds to the number of column of
> %the AIDA-output file
> [MchipsID, prim_sec, Name, Integral, Bkg, category,
> Label, Area, Integral_Bkg, Homogeneity, Saturated,
> Quality] = ...
> textread(source,'%s %s %s %s %s %s %s %s %s %s %s %
> s',numberOfRowsPlusHeader, 'delimiter', '\t');
> )
> elseif
> display('Reorder you file and start the program again!')
> end
>
> I always receive the following error message:
> ??? Error: File: aidaimportV5.m Line: 80 Column: 17
> Expression or statement is incorrect--possibly unbalanced
> (, {, or [.
>
> Can anyone help me?
>
> Corinna

Corinna, There are a couple of problems.
First, don't bother with the parenthesis around all of the commands.
MatLab keys off of the " if else end" words, not parenthesis. Second,
your follow on: You use elseif but don't have a condition. I think
you just want "else".

HTH,
Dan

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

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.

Tag Activity for This Thread
Tag Applied By Date/Time
lifestyle us 06 Aug, 2007 07:50:29
humor us 06 Aug, 2007 07:50:29
rssFeed for this Thread

envelope graphic E-mail this page to a colleague

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.
Related Topics