How can one specify a cell array or string array when your message has multiple lines of text?

If the title is confusing, then you're in the same place as me. I am attempting to create a uiconfirm figure in App Designer.
I have consulted the uiconfirm documentation page, and am having trouble with the message input arguement. The documentations says under message,
"Message to display, specified as a character vector, cell array of character vectors, or string array. Specify a cell array or string array when your message has multiple lines of text. Each element in the array corresponds to a different line of text."
My interpretation of this is that the message can indeed be a cell or string array, thus allowing it to display multiple lines. I cannot find any clarification on how one might specify that the arguement would be an array. I am attempting to pass a 1x14 cell array to the message arguement but MATLAB seems content with giving me the following error.
Error using uiconfirm (line 63)
'Message' must be a char array, string array or a cell array of character vectors.
Error in app1/UserInputConfirmationDialog (line 266)
uiconfirm(app.UIFigure,message,title, ...
Error in app1/StartButtonParamsPushed (line 350)
UserInputConfirmationDialog(app);
Error using matlab.ui.control.internal.controller.ComponentController/executeUserCallback (line 309)
Error while evaluating Button PrivateButtonPushedFcn.
I'm still somewhat new to MATLAB and I can understand that I may have interpreted the documentation wrong. Hopefully someone can offer me some clarification.

1 comentario

If my examples below do not help, please show us what your input variables look like.

Iniciar sesión para comentar.

 Respuesta aceptada

Here's are 3 examples that all produce the same confirmation figure.
Input: Cell array
f = uifigure;
msg = {'This is line 1 of message.', 'This is line 2', '', 'Line 4.'}; %{} makes cell array
selection = uiconfirm(f,msg,'My Title')
Input: String array
f = uifigure;
msg = ["This is line 1 of message.", "This is line 2", "", "Line 4."]; %[] with dbl quotes
selection = uiconfirm(f,msg,'My Title')
Input: Char array
f = uifigure;
msg = sprintf('This is line 1 of message.\nThis is line 2\n\nLine 4.');
selection = uiconfirm(f,msg,'My Title')

2 comentarios

The String Array example worked for me, what I had prior was:
msg = [{'example'}, {'example'}];
I guess I didn't fully understand how the array syntax was supposed to be written.
Thanks a bunch!
Hmmm that should have worked too. That produces a cell array of strings which is what my "cell array" example does.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Characters and Strings en Centro de ayuda y File Exchange.

Preguntada:

el 14 de Mayo de 2019

Comentada:

el 14 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