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:
What is unbalanced here?

Subject: What is unbalanced here?

From: Jeff

Date: 20 Nov, 2013 00:17:05

Message: 1 of 7

Why am I getting "Expression or statement is incorrect--possibly unbalanced (, {, or [." on the following line? It worked on another person's version of Matlab (I am using r2009a, he had r2012 or r2013).

[~,Types] = xlsread(latLongFile,'Types','A4:A160');

A possibly related question: what does the tilde (~) in the first return position mean?

Subject: What is unbalanced here?

From: dpb

Date: 20 Nov, 2013 01:26:07

Message: 2 of 7

On 11/19/2013 6:17 PM, Jeff wrote:
> Why am I getting "Expression or statement is incorrect--possibly
> unbalanced (, {, or [." on the following line? It worked on another
> person's version of Matlab (I am using r2009a, he had r2012 or r2013).
>
> [~,Types] = xlsread(latLongFile,'Types','A4:A160');
>
> A possibly related question: what does the tilde (~) in the first return
> position mean?

It's the new syntax to throw away unwanted return value and undoubtedly
the problem -- I'm not sure when it was introduced precisely.

Try

[N,Types] = xlsread(latLongFile,'Types','A4:A160');

and joy will likely ensue.

--

Subject: What is unbalanced here?

From: Steven Lord

Date: 20 Nov, 2013 18:28:39

Message: 3 of 7


"Jeff " <spREMOVEHITSjeffAT@SIGNoptonline.net> wrote in message
news:l6gv21$ph5$1@newscl01ah.mathworks.com...
> Why am I getting "Expression or statement is incorrect--possibly
> unbalanced (, {, or [." on the following line? It worked on another
> person's version of Matlab (I am using r2009a, he had r2012 or r2013).
>
> [~,Types] = xlsread(latLongFile,'Types','A4:A160');
>
> A possibly related question: what does the tilde (~) in the first return
> position mean?

That's the problem: the syntax that uses the tilde to ignore output
arguments was introduced in release R2009b. See the first entry in the
Programming section of the Release Notes for this release.

http://www.mathworks.com/help/matlab/release-notes-older.html#R2009b

As dpb suggested, replace the ~ with an actual identifier to avoid this in
release R2009a.

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Subject: What is unbalanced here?

From: Jeff

Date: 20 Nov, 2013 21:09:05

Message: 4 of 7

dpb <none@non.net> wrote in message <l6h33f$qjs$1@speranza.aioe.org>...
> On 11/19/2013 6:17 PM, Jeff wrote:
> > Why am I getting "Expression or statement is incorrect--possibly
> > unbalanced (, {, or [." on the following line? It worked on another
> > person's version of Matlab (I am using r2009a, he had r2012 or r2013).
> >
> > [~,Types] = xlsread(latLongFile,'Types','A4:A160');
> >
> > A possibly related question: what does the tilde (~) in the first return
> > position mean?
>
> It's the new syntax to throw away unwanted return value and undoubtedly
> the problem -- I'm not sure when it was introduced precisely.
>
> Try
>
> [N,Types] = xlsread(latLongFile,'Types','A4:A160');
>
> and joy will likely ensue.
>
> --
>

I went with
[unusedVariable,Types] = xlsread(latLongFile,'Types','A4:A160');

Subject: What is unbalanced here?

From: dpb

Date: 20 Nov, 2013 21:59:13

Message: 5 of 7

On 11/20/2013 3:09 PM, Jeff wrote:
> dpb <none@non.net> wrote in message <l6h33f$qjs$1@speranza.aioe.org>...
>> On 11/19/2013 6:17 PM, Jeff wrote:
>> > Why am I getting "Expression or statement is incorrect--possibly
>> > unbalanced (, {, or [." on the following line? ...
>> >
>> > [~,Types] = xlsread(latLongFile,'Types','A4:A160');
>> >
...

>> Try
>>
>> [N,Types] = xlsread(latLongFile,'Types','A4:A160');
...

> I went with
> [unusedVariable,Types] = xlsread(latLongFile,'Types','A4:A160');

In a case like this I'd stick w/ a much shorter name and then clear the
unused variable...

[unused,Types] = xlsread(latLongFile,'Types','A4:A160');
clear unused

Then you're not leaving anything laying around in the workspace that,
given the fact it's the result of xlsread() could be a fairly sizable
amount of stuff.

--

Subject: What is unbalanced here?

From: John D'Errico

Date: 20 Nov, 2013 23:15:06

Message: 6 of 7

dpb <none@non.net> wrote in message <l6jbbe$dm6$1@speranza.aioe.org>...
> On 11/20/2013 3:09 PM, Jeff wrote:
> > dpb <none@non.net> wrote in message <l6h33f$qjs$1@speranza.aioe.org>...
> >> On 11/19/2013 6:17 PM, Jeff wrote:
> >> > Why am I getting "Expression or statement is incorrect--possibly
> >> > unbalanced (, {, or [." on the following line? ...
> >> >
> >> > [~,Types] = xlsread(latLongFile,'Types','A4:A160');
> >> >
> ...
>
> >> Try
> >>
> >> [N,Types] = xlsread(latLongFile,'Types','A4:A160');
> ...
>
> > I went with
> > [unusedVariable,Types] = xlsread(latLongFile,'Types','A4:A160');
>
> In a case like this I'd stick w/ a much shorter name and then clear the
> unused variable...
>
> [unused,Types] = xlsread(latLongFile,'Types','A4:A160');
> clear unused
>
> Then you're not leaving anything laying around in the workspace that,
> given the fact it's the result of xlsread() could be a fairly sizable
> amount of stuff.
>
> --

A better solution yet is to use ans. It is the standard junk variable
anyway, so no need to even clear it.

[ans,Types] = xlsread(latLongFile,'Types','A4:A160');

Once ~ syntax was introduced, things got easier of course.

John

Subject: What is unbalanced here?

From: dpb

Date: 20 Nov, 2013 23:55:57

Message: 7 of 7

On 11/20/2013 5:15 PM, John D'Errico wrote:
> dpb <none@non.net> wrote in message
...

>> In a case like this I'd stick w/ a much shorter name and then clear
>> the unused variable...
>>
>> [unused,Types] = xlsread(latLongFile,'Types','A4:A160'); clear
>> unused
>>
>> Then you're not leaving anything laying around in the workspace
>> that, given the fact it's the result of xlsread() could be a fairly
>> sizable amount of stuff.
...

> A better solution yet is to use ans. It is the standard junk
> variable anyway, so no need to even clear it.
>
> [ans,Types] = xlsread(latLongFile,'Types','A4:A160');
>
> Once ~ syntax was introduced, things got easier of course.

That's a good idea for a transient variable name, John, I like that.

But 'ans' won't be cleared until something else uses it so inside a
function or a script it would still be holding the memory. Not that
memory is what it once was, but...

--

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