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 CenterFile Exchange에서 Develop 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