str2num error with text field

1 view (last 30 days)
Lucia Wagner
Lucia Wagner on 8 Jul 2020
Answered: Anirudh Singh on 13 Jul 2020
Hello MATLAB community!
I am receiving this error... Invalid expression. Check for missing multiplication operator, missing or unbalanced delimiters, or other syntax error. To construct matrices, use brackets instead of parentheses.
...for this line of code (marked with comment). Any suggestions would be quite helpful!
function TranslateXEditFieldValueChanged(app, event)
value = app.TranslateXEditField.Value;
switch app.ConeTypeSelected
x = str2num(get(app.TranslateXEditField, 'value')) % this line of code is receiving the error
case 1
case 2
case 3
dpb on 9 Jul 2020 does look like the parser state machine was going on trying to make an expression...what, specifically it did internally to generate the specific error I've no idea, of course. It may be one of those "when all else fails, hoist the white flag" and give up.
I just tried now (which I didn't earlier) -- in the editor, when you enter an executable statement inside the switch block but outside a case block you get a generic
parse error at {first word on line}: usage might be invalid MATLAB syntax.
which would be more informative probably if got that at runtime as well.
Shows shouldn't try to run code w/ red marks on RH column in editor! :)
Does look like this is one that ought to be able to be identified explicitly as
"code in the SWITCH not contained in CASE."

Sign in to comment.

Answers (1)

Anirudh Singh
Anirudh Singh on 13 Jul 2020
As said dpb, The statement is in a switch construct, but not inside a case block.
The MATLAB switch does not work like other language switch.
switch switch_expression
case case_expression
case case_expression
You can check the Tips on the given documentation:

Community Treasure Hunt

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

Start Hunting!

Translated by