scope of disp()

Hi there,
I am trying to call a function that uses several calls to disp() to print out several messages to the workspace. Let's call this function "function B". So, function B then gets called from function A. The problem?
When I call function B from the workspace, function B displays the messages correctly, but when I call function A from the workspace (which then calls function B), none of the messages show. How can I get the messages to show even if I call function B from another function?
Thanks in advance,
-E.

3 commentaires

Oleg Komarov
Oleg Komarov le 12 Avr 2011
I don't get this problem. Did you place function B within a if statement inside of function A?
Robert Cumming
Robert Cumming le 12 Avr 2011
sounds like function B is not getting called...
Put a break in the code to check that it is (or isn't...)
Elisa
Elisa le 12 Avr 2011
it is like this. I have a function, myfunctionB, that looks, more or less, like the listing below.
-0-0-0-0-0-0-
function [a, b] = myfunctionB(input)
a=3*input; b=4; disp('hello');
-0-0-0-0-0-
Very simple, no ifs, etc, just a display.
Then I have file myscriptA.m where I do
-0-0-0-0-0-0
disp('Now I'm going to call function B') [k, z] = myfunctionB(3);
-0-0-0-0-0-0-0-
But I never see hello displayed when I call myscriptA from the command line. If I just call myfunctionB from the command line, I get: >>hello
Like it should do, but not when function B is being called. Even tough it DOES get called.

Connectez-vous pour commenter.

Réponses (2)

Andrew Newell
Andrew Newell le 12 Avr 2011

0 votes

Did you notice an error message? A quote in the middle of a string should be represented by two quotes. Try this:
disp('Now I''m going to call function B')
[k, z] = myfunctionB(3);
Elisa
Elisa le 12 Avr 2011

0 votes

Nevermind, you guys were right! As it turns out myfunctionB wasn't as simple, I was calling it in such a way to execute a path with no display messages (the function is more complicated than what I wrote up there, actually), so they weren't showing because indeed the display path wasn't executing. Sorry for the bother guys.

1 commentaire

Andrew Newell
Andrew Newell le 12 Avr 2011
Feel free to accept this answer (just click on the Accept button).

Connectez-vous pour commenter.

Catégories

En savoir plus sur Scope Variables and Generate Names dans Centre d'aide et File Exchange

Tags

Question posée :

le 12 Avr 2011

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by