How do I insert strings into UITable cells and format them in app designer?

41 ビュー (過去 30 日間)
Dan Haberberger
Dan Haberberger 2020 年 4 月 29 日
回答済み: Sahithi Kanumarlapudi 2020 年 6 月 9 日
Hi,
I'm writing my first app in app designer, though that may be independent of the UITable question I have. I inserted a table using the designer that looks like this:
When the "Calculate Imaging" button is pressed, the items in the table ("Wavelength, Focus, Object to Lens," etc. are calculated from the user input on the left for each row. Here is an example of how I input the data to the table:
app.UITable.Data{1,1} = num2str(lambda1, 4);
app.UITable.Data{1,2} = num2str(focus1, 4);
However, I don't like the display at all and can't seem to format it no matter how much I searh the web. I really don't understand why this isn't easier, it should be painfully easy. Here are the things I'd like to do:
  1. Center the numbers in the column (something like app.UITable.Data.HorizontalAlignment = 'center' ?????)
  2. Increase the row height to separate the numbers more
  3. After increase in height, center the numbers in the row
  4. Change the color and font type of the column headers (whose default is incredibly hard to see)
Thanks ahead of time for the help!
Cheers,
Dan

回答 (2 件)

Sahithi Kanumarlapudi
Sahithi Kanumarlapudi 2020 年 6 月 4 日
Hi,
1.) You could use the 'uistyle' property to align the data in the rows to center. The following link has an example on how to do the same
2.) Regarding row height, there is no direct way to do that yet. You can change the FontSize property to change the row height. I have brought this issue to the concerned people and it might be considered in any future release.
3.) Regarding formatting the column headers, this is a known issue and the concerned parties may be investigating further.
  1 件のコメント
Dan Haberberger
Dan Haberberger 2020 年 6 月 8 日
Thanks, seems like that would work. Unforutnately it only came out in 2020a, so I don't have the uistyle property. Is there another way?

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


Sahithi Kanumarlapudi
Sahithi Kanumarlapudi 2020 年 6 月 9 日
Hi,
'uistyle' was introduced in R2019b.
If you use R2019a or previous releases, refer to the following information.
As an alternative to the display position of the data, consider converting the numerical value to a character string and changing it to right alignment, or adjusting the display position using space.
fig = figure;
uit = uitable(fig);
uit.Data = rand(5,3);
data = num2cell(uit.Data); % convert to cell array
data2 = cellfun(@num2str,data,'UniformOutput',false); % convert to characters
uit.Data = data2; % Left alignement
% Insert spaces
data2 = cellfun(@(s)sprintf('%*s',12,s),data2,'UniformOutput',false);
uit.Data = data2; % like center alignment
Hope this helps!

カテゴリ

Help Center および File ExchangeMATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by