Matlab does not return an error when variable does not exist.

Hello everyone. Hope someone can help:
I call a variable that does not exist (in Editor) and I do not get an error message. in the Command Window.
Did I disable this capability by mistake?

4 Commenti

More specific. In the lines below, variable modFracts does not exist. The program runs and stops when the variable is called, but no error message appears Command Window
____________________
modFracts
propMain = char(propMain); propSec = char(propSec);
valMain = num2str(modFracts(handles.ILXLPlt),3)
__________________
Any help is appreciated.
Which is the variable you're talking about? What is a "command issue"? Please post a screenshot showing
  1. your code editor with execution stopped just after you executed that line,
  2. the workspace so we can verify that the variable is not in there.
  3. the command window so we can see that no error was thrown.
This is the piece of code calling variable "modFracts" that is not in the workspace. Variable "propMain" does exist.
___
who propMain
who modFracts
propMain = char(propMain); propSec = char(propSec);
valMain = num2str(modFracts(handles.ILXLPlt),3);
stop
____
Following is what I see in the "Command Window"
___
Your variables are:
propMain
>>
___

Accedi per commentare.

 Risposta accettata

I've found out what the issue was.
The function where errors were not reported was called from another (main) program. It was called within a try-catch-end,
MATLAB apparently disables the error messages within the try-catch and routines run within it.
.

1 Commento

We could have told you that if you had shared the actual code instead of unrelated snippets. When there is an error, control passes to the catch block. But if in that block you choose not to do anything with the error (like print it out or whatever), then nothing happens - it just continues on with the line of code after the "end" of the catch block.

Accedi per commentare.

Più risposte (1)

So you're saying that modFracts does not exist and when you do
who modFracts
it does not echo anything to the command window. That is normal. If it doesn't exist, it doesn't write anything to the command window. However if you do
modFractsCopy = modFracts;
it should throw an error because you're trying to reference/use it. Does it throw an error?
Try adding an s:
whos
and tell us what it shows.

6 Commenti

Attached are the images for the code and the Command Window.
I added an s on both "whos propMain" and "whos modFracts". In another run also tried "clear modFracts" at the beginning of the piece of code - same results.
Lastly - I was getting an error previously when the program reached the "stop" command (line 235) since it is not a valid Matlab command. It is not throwing the error now.
whos will not show any output for functions.
Adding "which modFracts -all" indicates "modFracts not found" in the command window, yet does not throw an error when "modFractsCopy = modFracts" is executed.
I uninstalled and reinstalled MATLAB earlier today. No change.
Please attach a small snippet that I can run that illustrates the fact.
Why is modFracts and modFractsCopy not showing up in the Workspace if you executed that line of code? It should either show up there or throw an error.
Sorry for bombarding you with information. Your support is appreciated.
It looks like the issue goes beyond not throwing an error when a variable is not defined. It looks like it is not threowing error messages at all.
In the code image (attached), the program goes past "test 1". then it should give an error since "stopx" is not valid. It does not.
We can't run images, only code as text. Will check back later. Make it easy for us to help you, not hard.

Accedi per commentare.

Prodotti

Release

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by