A variable and a string in a table cell?

2 ビュー (過去 30 日間)
ssd dds erty
ssd dds erty 2020 年 12 月 9 日
コメント済み: Stephen23 2020 年 12 月 10 日
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.

採用された回答

Harry Laing
Harry Laing 2020 年 12 月 9 日
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 件のコメント
Stephen23
Stephen23 2020 年 12 月 10 日
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 2020 年 12 月 10 日
ipatTxt = sprintf('The Indicated Power at %d rpm',app.EngSpd);
You might also find this useful:

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDevelop Apps Using App Designer についてさらに検索

製品


リリース

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by