A variable and a string in a table cell?

2 visualizaciones (últimos 30 días)
ssd dds erty
ssd dds erty el 9 de Dic. de 2020
Comentada: Stephen23 el 10 de Dic. de 2020
I am designing an app, it has a table and i want to show a string and a variable in one cell.
ipat = {'The Indicated Power at' app.IPat , sprintf('%.2f',app.IPat) , ' kW'};
app.UITable.Data = [app.T ; ipat]
What i want is, The Indicated Power at value shown in a cell.

Respuesta aceptada

Harry Laing
Harry Laing el 9 de Dic. de 2020
You cannot have two different data types in one cell. I can see you're attempting to convert a number (I presume of type double) to a string, add some text and then want the overall string to be presented in a single cell in the table. I suggest trying num2str():
ipat = ['The Indicated Power at ', num2str(app.IPat), ' kW'];
I have no idea what app.T is, so I cannot advise on what app.UITable.Data = [app.T ; ipat] will acheive. Though if you only want the phrase (for example) "The Indicated Power at 100 kW" to be shown, then try:
app.UITable.Data = ipat;
  2 comentarios
Stephen23
Stephen23 el 10 de Dic. de 2020
ssd dds erty's "Answer" moved here:
Thank you very much Harry.
I first combine the number and text like you said and then put it to table cell.
It works.
ipatTxt= strcat('Indicated Power at' , num2str(app.EngSpd) ,'rpm');
ipat = {ipatTxt, sprintf('%.2f',app.IPat) , ' kW'};
Stephen23
Stephen23 el 10 de Dic. de 2020
ipatTxt = sprintf('The Indicated Power at %d rpm',app.EngSpd);
You might also find this useful:

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Develop Apps Using App Designer en Help Center y File Exchange.

Productos


Versión

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by