A variable and a string in a table cell?

2 views (last 30 days)
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.

Accepted Answer

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

Sign in to comment.

More Answers (0)

Categories

Find more on Environment and Settings in Help Center and File Exchange

Products


Release

R2018a

Community Treasure Hunt

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

Start Hunting!