Unable to change label text via code

Hello,
I have created several labels using app designer but whenever I try to change a label text within a callback of a button it gives me an error for the equal sign '='
app.label9.Text = 'Incorrect values';

7 comentarios

Adam Danz
Adam Danz el 8 de Mayo de 2019
From appdesigner, select the red-underlined equal sign and press ctrl+m. It should tell you why it's underlined. What does that message say?
Basem Nabil
Basem Nabil el 8 de Mayo de 2019
it says "Invaid syntax at '='. Possibly, a ),} or ] is missing."
Adam Danz
Adam Danz el 8 de Mayo de 2019
Editada: Adam Danz el 8 de Mayo de 2019
That's what I thought. So somewhere in your code above that line you're missing one of those closed-grouping characters. Here's an example that recreates your exact problem:
t = [1:100; % <---- missing the closed bracket "]"
a = t(1:10);
Well, I had it inside else container. I moved the code outside else and it didn't give me that error. I think it's an issue within the syntax of if
isn't that the correct syntax?
if (condition)
{
//CODE
}
else
{
//CODE
}
end
Walter Roberson
Walter Roberson el 8 de Mayo de 2019
MATLAB does not use {} for code grouping, only for creating or indexing cell arrays.
Basem Nabil
Basem Nabil el 9 de Mayo de 2019
Thank you, I'm just used to other languages which use braces for block of code.
however, I've experienced another issue. The code works now but displays '...' instead of the text I assigned it to be. Do you have any clue why this happens?
Walter Roberson
Walter Roberson el 9 de Mayo de 2019
I believe that can happen if you have set text that is wider than the width the control has been set to.

Iniciar sesión para comentar.

 Respuesta aceptada

Adam Danz
Adam Danz el 8 de Mayo de 2019
Editada: Adam Danz el 8 de Mayo de 2019
(Continuing from comments under question)
That's not matlab syntax. Looks like cpp. If you have this opened in your matlab editor, it should be lighting up like Rudolph with red underlines.
Correct way:
if condition
% code
else
%code
end

Más respuestas (0)

Categorías

Productos

Etiquetas

Preguntada:

el 8 de Mayo de 2019

Comentada:

el 9 de Mayo de 2019

Community Treasure Hunt

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

Start Hunting!

Translated by