A variable and a string in a table cell?

2 vues (au cours des 30 derniers jours)
ssd dds erty
ssd dds erty le 9 Déc 2020
Commenté : Stephen23 le 10 Déc 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.

Réponse acceptée

Harry Laing
Harry Laing le 9 Déc 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 commentaires
Stephen23
Stephen23 le 10 Déc 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 le 10 Déc 2020
ipatTxt = sprintf('The Indicated Power at %d rpm',app.EngSpd);
You might also find this useful:

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Environment and Settings dans Help Center et File Exchange

Produits


Version

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by