From: gunther on
Hello everybody,

I want to call the function tone.m that produces a special beep sound conditional
on statement A

if A==1
tone.m
else
???
end

What do I have to write after 'else' to make Matlab no to call tone.m????

Or, is there another and better way to do this???

Many thanks
Gunther
From: Oleg Komarov on
"gunther " <forben(a)web.de> wrote in message <huqupb$nuf$1(a)fred.mathworks.com>...
> Hello everybody,
>
> I want to call the function tone.m that produces a special beep sound conditional
> on statement A
>
> if A==1
> tone.m
> else
> ???
> end
>
> What do I have to write after 'else' to make Matlab no to call tone.m????
>
> Or, is there another and better way to do this???
>
> Many thanks
> Gunther

Nothing.

if A == 1; tone; end

Oleg
From: Steven Lord on

"gunther " <forben(a)web.de> wrote in message
news:huqupb$nuf$1(a)fred.mathworks.com...
> Hello everybody,
>
> I want to call the function tone.m that produces a special beep sound
> conditional
> on statement A
>
> if A==1

This will execute the body of the IF, assuming that ALL the elements of A
are equal to 1.

> tone.m

This will not work; to call a function you need to either:

* just use its name, like:
tone;
* or use its name followed by parentheses containing input arguments to be
passed into the function:
tone();

The code you wrote will attempt to treat tone as a struct array or object
and retrieve the m field from that struct array or the m property of the
object; if tone is neither of those types of variables, you will receive an
error.

> else
> ???
> end
>
> What do I have to write after 'else' to make Matlab no to call tone.m????

Nothing. In fact, you don't even really need the ELSE block:

if A == 1
tone;
end

But if you wanted to use the ELSE for whatever reason (like you were
planning at some future time to insert some code) you could simply use
nothing at all (or a comment explaining that you've inserted the ELSE for
future expansion):

if A==1
tone;
else
% leaving this empty for right now
% TODO: fill in the code for the case where A is not 1
end

--
Steve Lord
slord(a)mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
To contact Technical Support use the Contact Us link on
http://www.mathworks.com


From: Loren Shure on
In article <huqupb$nuf$1(a)fred.mathworks.com>, forben(a)web.de says...
> Hello everybody,
>
> I want to call the function tone.m that produces a special beep sound conditional
> on statement A
>
> if A==1
> tone.m
> else
> ???
> end
>
> What do I have to write after 'else' to make Matlab no to call tone.m????
>
> Or, is there another and better way to do this???
>
> Many thanks
> Gunther
>

First, you call tone.m by typing tone. Second, if A isn't 1, what do
you want to have happen? Nothing? Then write this:

if A == 1
tone
end

--
Loren
http://blogs.mathworks.com/loren
http://matlabwiki.mathworks.com/MATLAB_FAQ
From: Jan Simon on
Dear Gunther!

> I want to call the function tone.m that produces a special beep sound conditional
> on statement A
>
> if A==1
> tone.m
> else
> ???
> end
>
> What do I have to write after 'else' to make Matlab no to call tone.m????
> Or, is there another and better way to do this???

At first I'd suggest to read the "Getting started" section of the documentation.
Then "help if" gives some advices also.

There is no specific command to let Matlab do nothing. But you can just omit the command at all!
if A == 1
tone; % Without ".m"
end

Good luck and welcome to Matlab, Jan