# Tables in MATLAB with uitable95

I’d like to welcome guest blogger Denis Hanson from the GUI Building team. Denis will occasionally be blogging here on the Inside the MATLAB Desktop blog.

In R2008a, we added the uitable control, as well as support for this new control in Guide. The uitable component enables the display of data in a two dimensional table. You can use the Property Inspector or the new Table Property Editor to get and set uitable object property values (to open the Property Inspector type inspect at the command prompt; to open the Table Property Editor, right-click your uitable in Guide and select Table Property Editor…).

The Table Property Editor makes it easy to define the layout of a table inside Guide. The Property Inspector could be used to achieve the same results, though it’s not targeted to uitable. Lets look at using the Table Property Editor to setup a uitable.

Table properties fall into four natural categories, which are presented on separate panels. Here’s a listing of each of the Table Property Editor’s panels, and what you can do on each:

• Columns – set column names, format, size, and editability
• Rows – set row names
• Data – select data to display in the table
• Colors – set colors and control row striping

Notice also that at the top of each panel is a help section. The text in the panel will change to reflect the option that is currently selected on the property panel.

Let’s look at each of the panels in detail.

Columns Panel

The Column Headers section of this panel lets you control how and if column headers are displayed. The Column Definitions section of this panel lets you tweak properties for each column and also allows the insertion, removal and rearranging of columns.

The Format column in the Column Definitions table specifies how the data should be formated for viewing. Here are each of the options and what they do:

• Let MATLAB Choose – MATLAB chooses a format that most closely matches the underlying column data. For example, if the data in the column is doubles, the Numeric display option will be used.
• Choice List – allows you to enter a series of series of values that will be displayed in a popupmenu. This option is especially useful if the column is editable and you want to restrict the values that they user can enter.
• Format – lets you choose from a pre-defined list of formats for displaying numeric data. The options are the same as those found in the format function.

Rows Panel

The Rows panel lets you define how row headers are displayed. Row headers are shown in an additional column at the left edge of the table. They do not contain table data values. If shown, they typically display the row number, but you can enter a custom name for each row.

Data Panel

The Data panel lets you populate the table with data from workspace variables. A table row will be created for each row in your data set and a table column will be created for each column in your data set. Once you have saved the data into the table, the table contains a copy of the data. The table data is not linked to the workspace variable so further modifications to the workspace variable will not be reflected in the table.

The values you set here are used to populate the table when your figure is displayed. This is useful if you have canned data that does not change. If your data is not fixed, you should select the Do not set data value and leave the table empty option. You will then need to load table data programmatically.

Colors Panel

The Colors panel lets you define the background, foreground, and row-striping colors used to paint the cells in the table. When row-striping is on the table paints odd and even rows using different background colors. The striping effect makes it easier for a user to scan the data in a table row, especially if there are many rows of data.

This was a world-wind tour of the new uitable control – in a future post, we’ll show you how to use the new control in a real application.

Let us know what you think about uitable!

-by Denis Hanson, The MathWorks

### Note

Oliver A. Chapman, P.E. replied on : 1 of 95

Denis,

Thanks for the column. But, I’m having trouble following the beginning. I’ve made some GUIs & untables before, but never with Guide. So, I follow you instructions: I type “inspect” and fired up Guide. But, I don’t see my “uitable” in Guide. Besides that, Guide seems to default into some generic figure, not a GUI.

What am I missing?

Ken replied on : 2 of 95

Hi Oliver,

Make sure to start up Guide first, then create a uitable from within Guide (rather than creating on from the command line first). When Guide first starts up, you’ll have a blank figure window on which you can drag UI controls.

-Ken

Moran replied on : 3 of 95

Hi Ken/Denis,

Thanks! This addition is very useful.

However, there is one thing that seems to be missing – can you get the selected row or column identifiers? This would be really useful when using uitable to present a database from which the user can extract specific rows.

I see that ‘evendata’ returns the selected indices, but is there a way to get this as an object property?

Thanks!

Denis replied on : 4 of 95

Hi Moran,

The current version of uitable does not contain properties for selectedRow and selectedColumn. These properties are at the top of our list of enhancements for uitable.

You can use the values in CellSelectionCallback’s eventdata to track the selections as they occur, saving the selection indices into workspace variables.

-Denis

Liang Zhimo replied on : 5 of 95

thank you for your column,but I still have a little trouble on it:when I use a table in a form which is used to input a matrix, I don’t know how to fix the column or row size of the table by command line (not inspector).Could you give me some advise?

Denis replied on : 6 of 95

Hi Liang,

To control the column widths from the command line you use the set command. Here is an example that sets the first column to 100 pixels, the second column to 60 pixels, then autosizes the third column.

set(uitable_handle, ‘ColumnWidth’, {100 60 ‘auto’})

To make all columns in a table use autosizing, use

set(uitable_handle, ‘ColumnWidth’, ‘auto’)

As these examples show, the value for ColumnWidth is either a 1–by-n cell array or ‘auto’. The width used for ‘auto’ is the greater of (a) the width of the column header, and (b) 75 pixels.

There is no property to control row size.

bswang replied on : 7 of 95

I use a uitable in guide. The uitable works well on the matlab environment. But when i build the mytest.m into the mytest.exe, the uitable doesn’t work because the data in the uitable can’t be displayed. why?

Mike replied on : 8 of 95

bswang,

Depending on where your data is coming from, it may not be available from your standalone program (e.g. importing from a text or mat file that is located somewhere relative to your inside-MATLAB session, etc). Or, if you have multiple MATLABs/MCRs installed, the runtime environment may be different than what you expect.

What you should do is dump the data to the console to verify that the data is actually available inside your program. If that works, you should open a help ticket with tech support so they can help you resolve the UI issue.

Etienne replied on : 9 of 95

Hello,

Is it possible to change the background color of a particular cell?

Ken replied on : 10 of 95

Hi Etienne,

It isn’t currently possible to change the background color of a particular cell in a uitable – I’ve created an enhancement request for this.

Note that you can change the background of all the cells, described in the doc for uitable

-Ken

Yong Yang replied on : 11 of 95

Hello,
In the standalone application, the data of the uitable control can not display. Why does it happen?

Ken replied on : 12 of 95

Hi Yong,

-Ken

din replied on : 13 of 95

hello…may i know about matlab command(absolute command)….i aready has the prog…but they use command table1 / table2…..matlab say that command aready absolute….so…may i know the latest command to replace table1 or table2 command?

Gary replied on : 14 of 95

Hello,

I have created an user interface with an Uitable for user to input some parameters and then click on an “OK” button to finish entering data (I don’t expect the user to click on a cell then click on “OK” to finish). The Uitable and the “OK” button are on the same figure. My problem is that the Uitable can never retrive the last cell edited, no matter I use CellEditCallback or CellSelectionCallback. I use KeyPressFunction to collect the last data, but it won’t work if the user just want to edit a single number of one cell. Is there any workaround you can suggest? I’m using R2008a. Thank you.

Gary

Ken replied on : 15 of 95

Hi Gary,

The edits to a cell aren’t committed until the cell loses focus. Could you explain in more detail what you are trying to do?

-Ken

Tony replied on : 16 of 95

Hi Gary,

I ran into the same problem as did Ken. Here is my scenario and perspective, perhaps this can help describe at least a similar issue.

“Note In order for the CellEditCallback to be issued, after modifying a table cell the user must hit Enter or click somewhere else within the figure containing the table. Editing a cell’s value and then clicking another figure or other window does not save the new value to the data table, and does not fire the CellEditCallback.”

I have an “OK” button *within* the same figure. Therefore, I would expect the CellEditCallback function to be called after entering a value in a cell and then clicking “OK.” However, this does not happen. I too would appreciate a possible work-around.

Tony

Tony replied on : 17 of 95

Hi Ken,

Please excuse me. I interchanged your name with Gary’s in the above note. (I meant to address the above note to you, and state that my problem is similar to Gary’s.) I too am running R2008a.

Also, to refine my point, I expect that when I click “OK” after editing a cell, this click would cause the edited cell to lose focus, and since I am clicking within the same figure, I would expect the CellEditCallback to be issued.

Thanks again,
Tony

Ken replied on : 18 of 95

Hi Tony and Gary,

Unfortunately, there is a bug in R2008a that prevents the cell edit from being committed on table focus lost. The only work around is to click on another cell. This has been fixed in R2008b.

-Ken

MooS replied on : 19 of 95

Hello,

Is it posible to highlight (select) a cell using the object handle of the uitable (e.g. by commands in the ‘base’ workspace). I have two figures, one with the table and one with a surface. I would like to show which point in the surface matches to the cell in the uitable by clicking in the surface….

MooS

Ken replied on : 20 of 95

Hi MooS,

There is not currently a way to programmatically set the selection in a uitable. Please submit an enhancement request here.

-Ken

MooS replied on : 21 of 95

Hi Ken,

Just submitted the request. Hope the functionality will be added soon. Thanks for your help!

-MooS

Nadia replied on : 22 of 95

Hello,
I’m working with a uitable object in Matlab 2008b.
I would like to know how to reference each cell (with column and row, I guess…).
Is there a way to Enable/Disable a full row depending on the value of a logical cell (true/false)???

Thank you!

Ken replied on : 23 of 95

There isn’t yet a way to reference each cell or disable a particular row. You can request that feature here.

-Ken

Tim Doyle replied on : 24 of 95

Hi I am trialing R2008b at the moment and am really liking the uitables!

One question though. Can I clear the selection of data from the table. That doesn’t make sense at all! Ok here’s the problem.

Open a data file, display in the uitable. User selects some data does stuff with it. While that data is still selected in the table, the user opens a new file, the CellSelectionCallback seems to get called on the new data, which is different, (actually I think it is trying to reference data that is not there until the new data loads) consequently I get an error (index out of bounds).

So lets say columns 2 and 3 from row 8 to 108 are selected. When I load a new file I want there to be no selction.

Does that make sense?

Is this possible?

Thanks,
Tim.

Tim replied on : 25 of 95

Hi there.

I have remodelled a program using gui of matlab. Everything works fine. The only real problem i have is that when i am using uitable in a figure to let the user store data in, the last data entered is not saved if the user does not press enter or selects something else in the uitable before exiting the figure (by pressing a button). I really want this to be done automatically since the users keep making the same mistake. Is there a way to trigger matlab to select something else or confirm a data change some other way?

Tim R.

Ken replied on : 26 of 95

Hi Tim,

There is a bug in R2008a that prevents the cell edit from being committed until focus is lost. This has been fixed in R2008b.

See my previous comment on the issue here.

-Ken

Javier Rivera replied on : 27 of 95

To whom ever may concern,

How can I load data into uitable created by guide such that it loads and displays the data matrix without the cliking on the cell and after the table has been created?

Is there a update table callback function (no keystroke or mouse click required)? If so where is it?

Thanks,

Javier Rivera
PS. Sample call below:

function uitable1_CellSelectionCallback(hObject, eventdata, handles)
% hObject handle to uitable1 (see GCBO)
% eventdata structure with the following fields (see UITABLE)
% Indices: row and column indices of the cell(s) currently selecteds
% handles structure with handles and user data (see GUIDATA)

data = get(gcbo,’Data’);
data(1,1) = {‘intSTALength’};
if ~isempty(handles.intSTALength)
data(1,2) = {num2str(handles.intSTALength)};
end

set(hObject,’Data’,data);
% Choose default command line output for tegui2
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);

% Only works if you click on cell (cell edit)

Javier Rivera replied on : 28 of 95

Never mind the question #27 above, it can be handled using

set(handles.uitable1,’Data’,data)

rather than a call back.

Thanks,

Javier

Morris Hirsch replied on : 29 of 95

It would be useful if the names column (or any column) could hold things other than text, like a Checkbox or Pushbutton.

In my application, the rest of each row would have data, but the controls would show which are “active” or some other attributes.

Without this ability, I can put the controls in a separate panel next to the table, and hope they stay aligned on resizes.

Ken replied on : 30 of 95

Hi Morris,

I will pass along your request.

-Ken

Sevin replied on : 31 of 95

Hi,

Is it possible to show the Data in a uitable centered? The data format in my uitable are only integer or “bank” (fix dollar ant cents). The column titles are centered by default but the data is not. How can I make both centered?

Also, is there a way to chnage format of a cell in an uitable? For example, cell(4,10): bold.

Thanks…

Ken replied on : 32 of 95

Hi Sevin,

I consulted with the uitable experts on this one and here’s what they told me:

1) Currently, there is no way to set the alignment for each column. The alignment will be determined based on the data type, unless you set the column’s ColumnFormat property. We are working on allowing users to specify the alignment of a given column.

2) There is no way to change the format for a cell (we do have an enhancement request for this).

-Ken

Arne replied on : 33 of 95

Hi,

i have created in GUIDE a table with the tag “uitable1” and 4 additional editable fields for input values.

1. In which location of the m-file i can renamed (or set a new variable/tag) for the uitable1 to “t1”?
2. How can i adress the uitable “t1” in the m-file and fill some fields with the results from the 4 fields? With a matrix A (2×2)?

thx and greetz from germany

Arne

Mike replied on : 34 of 95

Arne,

1. With a GUIDE-generated gui the easiest way to rename (change the Tag) a control is with the Property Inspector in GUIDE. To do it from the MATLAB-file you have to export the GUI from guide to a single file (instead of a .fig and .m) and find where the uitable is created and change the tag from “uitable1” to whatever you want it to be.

2. With a GUIDE-created gui you can access the handle for any control from the handles object that is passed in to all the callbacks. For instance if your table tag is “uicontrol1” then

set(handles.uitable1,'Data',eye(2));

will set the data for you. Let’s say you wanted to wanted to initialize your table, t1, with A when the GUI loads. Then in the gui_OpeningFcn you would use:

set(handles.t1,'Data',A);
Phillip replied on : 35 of 95

Hi Ken or Mike,

I have a user interface that uses a uitable to display messages to the user. Each time an event occurs it is logged in the uitable and shown to the user. What I am wondering is:

Is there anyway to make the uitable stay “scrolled down” all the way?

The reason I ask is as the number of events, the list, becomes big enough the uitable cannot show them all. That not a big deal, but since newest events are shown at the bottom of the uitable the user must scroll down to see them.

Thanks for the help!

Ken replied on : 36 of 95

Hi Phillip,

Unfortunately, programmatic scrolling of a uitable is not supported yet. I’ve created an enhancement request for this.

-Ken

Philippe replied on : 37 of 95

Hi Ken and Mike

Can you tell me if the feature you requested at point 10 is available in Release 2009b? Or is there another workaround rather then using html to set the color of a particular cell content?

Thanks

Ken replied on : 38 of 95

Hi Philippe,

It doesn’t look like the “change background color of cell in uitable” is going to make it in for R2009b, so you’ll have to continue using the HTML workaround for now.

Sorry,
-Ken

Stephen replied on : 39 of 95

Hi Ken and Mike,

I am trying to create a finite element analysis program using matlab R2008a which uses a uitable for the user to input various numerical inputs for a simple structure.

Having made the table in GUIDE I am struggling to retrieve the data to manipulate it in an m-file. Would you be able to advise the syntax for this.

Many thanks,
Stephen

Louis Fernandes replied on : 40 of 95

If I type in a cell, for example, 1.234567, then the cell displays (using the my default numeric format) only four decimal digits: 1.2346 . This is fine in order to have a clear display of the data. However, when I collect the data from the table, get(tablehandle,’data’), the collected value for the calculations is 1.2346, not the value 1.234567 that I entered. This adversely affects the precision of the calculations. Is there a way that the table keeps the whole number, but it only shows four decimal digits?. I want to avoid using “format long” because then the table gets too crowded.

Thank you very much
Louis

X-Ray replied on : 41 of 95

Hi Folks,

I am using MATLAB R2008a to create a GUI in windowsXP. I have the same problem two of the users already commented. When I use the deployment tool to build a standalone application .exe program from the .m file, all uitables, no matter in subGUIs or mainGUI, will not display the data. the column and row numbers of those tables match exactly the data, but the cells are simply blank. The data is in the program, and I double checked by printing them in a static text box. Is it a bug of MATLAB?

TT replied on : 42 of 95

Does some of question solved in Matlab R2009a? Such as get or set data on cell level?

matlabfinance replied on : 43 of 95

Ken:

What is the HTML workaround that you talked about for coloring idividual cell in uitable. Please let me know.

Ken replied on : 44 of 95

Hi matlabfinance,

Right now, the only way to get the background color of a cell to change is to wrap your cell data (‘foo’ in the case below) in HTML like this:

x = {'<html><font bgcolor="yellow">foo</font></html>'}


-Ken

Daniel replied on : 45 of 95

Is there any way to add a greek characted (Δ, ε, and so on) into the name of columns and/or rows? I have tried typing in latex commands but didnt work. I dont think theres a way to do this with matlab huh?

Mike replied on : 46 of 95

Daniel,

You can use Ken’s aforementinoed html trick to insert unicode characters. For instance ‘ε’ is x03B5, so the cell data would be:

'<html>&#x03B5;</html>'
Daniel replied on : 47 of 95

Hi Mike, hi Ken,

Do you know if it is also possible to introduce subindices? In latex what im looking for would be something like ‘\Delta_{pb}’

Daniel

Daniel replied on : 48 of 95

Hi Mike,

‘Δpb’

Thanks you!

Malek replied on : 50 of 95

I used the -a in the mcc for the codetools. But the tables did not update whenever I filled it using data I got from a database Table. So I simply entered the data twice.

set(handles.uitable2,’Data’,count_alarm)
set(handles.uitable2,’Data’,count_alarm)

and it worked! I hope it works for you guys

Malek replied on : 51 of 95

I am sorry for the previous post… It is still not working…
:)

adiel replied on : 52 of 95

hi mike & ken.

i’de like to know how can I use in the information that the user write in the table?
and if I can chenge what he wrote from the program?

Mike replied on : 53 of 95

You can use the get and set methods on the ‘Data’ paramater of the uitable handle to read/write the data.

salem replied on : 54 of 95

i design a matlab program with user interface by using gui and i input the data from the user interface but i have problem to read the data from uitable
fro example when i need to input data from fig to m file i use
str2double(get(handles.edit11,’string’)); this to read data i input it through edit but when i need to read data from table what is the order that i write it in m file

Phil replied on : 55 of 95

I have the same problem as described above with UITable working fine in the Matlab environment but showing no data when compiled as an executable.
The data is definately present in the table, as I select a line of the table and other fields change their contents to reflect the line of the table which has been selected. So the cells seem to have data in, but they appear empty.
I have seen this problem posted several times but no solution. Is this a MATLAB bug which remains unsolved?

Nelson replied on : 56 of 95

I have a suggestion regarding column formatting:

Support fprintf type format strings for numerics, such as ‘%.4g’.

Thanks.

Greg replied on : 57 of 95

OK, count me in as another person who can not get the uitable to show data in a DEPLOYED application. Anyone have this working? Release 2008a

Phil replied on : 58 of 95

I still have not found a solution to the problem of the MATLAB table not showing data in an executable. However, there is a JAVA table object available which you can overlay over the MATLAB table and transfer data from the MATLAB table to the JAVA table every time the data in the table changes. This works very well. It is a shame that MATLAB have not fixed their own table object though.

Jason replied on : 60 of 95

in the old undocumented version of uitable there was a property under the table at: uitable.Table.setAutoResizeMode

this caused the cells to spread to the width of the control, now the set(uitable,’columnwidth’,’auto’), is similar, but the outcome is different. is there a way to replicate the old setAutoResizeMode?

Thanks
Jason

Patrick Tai replied on : 61 of 95

Two questions on uitable in GUIDE: (ML 2008a/b)
1. How to control the column width of the column of row-headers (not data cols)? The default width is too wide.
2. If the column header is ‘A|B’, it is displayed as:
A
B
How do you display it as literally ‘A|B’? (A\|B fails)
Thanks.

Jean replied on : 62 of 95

Hello, I am using the R2008a. I created a gui using GUIDE. I set the gui ‘Resize’ proportional, however the table in the gui has not changed when I change the size of gui. Do you guys have any suggestion on that?

Thanks a lot!!

Mike replied on : 63 of 95

@Jason,
That functionality is not available yet in the new version of uitable. Setting the columnWidth to auto allows MATLAB to choose the width of the column and does not affect the resize mode. If you can email me some more detail about how you were using the old undocumented resize property I can relay that to the developers for their planning of the next iteration.

@Patrick and @Jean,
I don’t know all the details of uitable and will get answers from its developers as soon as I am able. Thank you for your patience. If you need a quicker answer I suggest posting your question to the comp.soft-sys.matlab newsgroup (see the “Newsgroup” link at the top) or by contacting Technical support. Thanks for your questions and patience.

Joanna replied on : 64 of 95

@Greg and @Phil
FYI, Starting R2008b, uitable could show data in a DEPLOYED application.

sayyed hamed replied on : 65 of 95

it was great for me as a beginner
thank you.

Mike replied on : 66 of 95

@Jean,

I have some follow-up questions that will help answer yours. What does it mean when you change the size of GUI: do you change the ‘position’ property or drag the figure?. You said the table in GUI has not changed, what do you expect to change, the size of table or table column?

Paulius replied on : 67 of 95

I can’t find an example for the best way to validate data newly-entered in a uitable cell. Is the below right, or is there a better option? (Aim: New cell value must be at least as large as the value in the fist cell of the previous row.)


newdata = eventdata.NewData;
if isempty(newdata)
return
end

idx = eventdata.Indices;
table = get(hObject,’Data’);
if idx(1,1) > 1 && newdata < table(idx(1,1)-1,1)
table(idx(1,1),idx(1,2)) = table(idx(1,1)-1,1);
set(hObject,’Data’,table);
end

If this is right, it would be a useful example to include in the documentation!

Mike replied on : 68 of 95

@Paulius,

I can’t say if your method is right without more context. However the CellEditCallback is the place to put validation logic for when the user edits the data in a table.

Paulius replied on : 69 of 95

Perhaps I should clarify my concern. My code takes a copy of the table data, changes it, then writes it back to the table. This seems an inefficient way of changing just one cell value, but it also seems the only way to do so. Is that right?

A new question: I discovered that if I issue an error message (by modifying the String value of a text control), the table loses focus. The documentation says focus may be restored using uicontrol(hObject), but this doesn’t seem to work. If I use set(hObject,’Selected’,’on’) instead, focus is restored to the table but not the last edited cell. Am I missing something (is there another way?), or is this a limitation of the current implementation of the uitable control?

Paulius replied on : 70 of 95

Looks like that’s exactly the correct way to handle data in a Matlab GUI: get(), modify, then set(). Not very efficient, but my biggest complaint is that it’s not well documented as a procedure. And tables do indeed seem more limited (and buggy) than other gui controls. I guess we should be happy they exist at all, and that there are work-arounds for the most important issues.

Adrian Sapio replied on : 71 of 95

Hello, I am creating a GUI using a uitable. Some questions:

1) I would like the delete button to delete the contents of a cell, as is commonly done in MS Excel. I am trying to implement this but havent been able to figure it out.

I considered adding some code to the keypress callback that clears the contents, but that code would also be invoked when someone is editing the cell and hits delete. In that case, only one character is deleted (this is already built in to the uitable object). When the cell is not being edited (just has focus, or is selected) I would like the delete key to clear the cell contents, but not in the other case. Is there some table property that would allow me to differentiate between these two cases when delete is pressed?

2) I have seen some 2008 posts above about the cell focus going back to (1,1) whenever any table data is edited. I am having this problem too, this is quite annoying for the user. I cant find a way to prevent this. Has this issue been addressed?

3) In general I would like to programatically set which cell is selected. It seems some users above do also, is this possible yet? Or do you know a trick to doing this?

Thanks!

John Pamar replied on : 72 of 95

Hi guys,

Great tutorial. I created a GUI in MATLAB R2008a on Win XP using GUIDE and my GUI has a table in it. When I tried running my GUI on a MAC OS X with MATLAB R2007b, the error “unrecognized object type: uitable” occurred, which is understandable since the old undocumented version of uitable is the only version available on R2007b. What is the best way to remedy this problem? Is there some way I can update the MATLAB R2007b without having to hard-code using uitable(…) function and all the properties? Thanks for any advice.

Mike replied on : 73 of 95

@John,

There’s no easy workaround, in fact I can’t even think of anything other than difficult workarounds using lots of undocumented functionality. However the smarter brains at CSSM might have some ideas.

Chintan replied on : 74 of 95

Hi Ken,

In reference to response 44, is there a way to replace ‘foo’ by a variable, so that I can display a value contained in the variable.

I am not aware of html format and hence was wondering if that is possible

Ken Orr replied on : 75 of 95

Hi Chintan,

I think the following should work (Mike can correct the code if it’s wrong):

x = {['<html>' myVariable '</html>']}

-Ken

Mike replied on : 76 of 95

@Chintan and Ken,

I haven’t tried it yet, but you’ll want to use num2str around the variable(assuming it’s a 1×1):

x = {['<html>' num2str(myVariable) '<html>']}

or

x = {[sprintf('<html>%d<html>',myVariable)]}
Gev replied on : 77 of 95

Hey all,

I’m having a prolem clearing uitable cells content.
The uitable i use is only for displaying data (without editing it).

As the user presses the ‘clear’ button, i would like the cells values to disapear.

clear(handles.table) or clear(handles.table,’Data’) doesn’t work i think because handles.table is not a string.

any help ??

thanks.

Gev

Mike replied on : 78 of 95

@Gev,

clear removes variables from the workspace, what you want instead to make the Data property empty. Try:

 set(handles.table,'Data',[])

Gev replied on : 79 of 95

Mike .
It works just fine!
[] is important there..
Thanks a lot ..
Gev

Eve-Marie replied on : 80 of 95

Hello there,

I really like the table but I am having some issues with it…
1. I use the table to display a list. For some reasons, if the list is too long (more rows than the number of rows displayed), it automatically put a scroll bar width wise…(height wise is expected but not width wise) – is there any way to fix this? (all my columns are fixed format, not auto)
2. If I export my GUI to another machine, the table doesn’t keep its original size and I either obtained a table with 2 scroll bars or I have a grey area on the sides… I have seen a post (someplace else) about using normalized units instead of pixels but he had no luck doing this either… Would you have a suggestion?

Thanks,
Cheers,
Eve

Jeff H replied on : 81 of 95

Hello, I have created a table that is nicely displayed, but when I export or print it (e.g. print(hndl, filename, ‘-dmeta’) or print(hndl, filename, ‘-depsc2’)), I get a bitmapped image, including fonts, that looks bad, instead of the vector graphics that I want. I have tried all 3 renderer choices, and printing a figure with no UIControls works fine. Is there a way to print or copy the table in a vector graphics format?
[Using ML R2010a, Win7]

Pedro replied on : 82 of 95

hello
i’m a newb using r2009a

my question:
how do i change the number of row ?
i don’t see any option in the property to define the number of row.
so what i do is checklist the “show name entered below..” under the rows option and fill the field with number just exactly beside that field.

Other possible way is to assign the data with particular value in workspace. But that means the table is filled, not empty.

Is there any other way to define the number of rows?

thanks.

Staffan replied on : 83 of 95

Hey,

I have the same problem as in post 61: the column of the rownames is far too big. Is there any workaround to set the columnwidth of the rownames? please help… thanks!

Staffan replied on : 84 of 95

…another problem is the fontsize of the rownames of the uitable. it appears that I can not set the fontsize to values below 11 pt. If I try, it does not change size below 11 pt. Any ideas?

Kent replied on : 85 of 95

Every time I repost data to a uitable, the ColumnWidth resizes to the original definition, vitiating the “user customizability” of uitable column widths. Is it possible to “get” a uitable’s CURRENT ColumnWidth, reflecting the users customization? If not, is there any other way to make the table “remember” the ColumnWidth changes that a user may have applied.

karin replied on : 86 of 95

hi, i’m using a “uitable ” to insert data to a GUI, i need to save the data on a matrix for the internal use of the program. i’m trying to insert the data using a “get(…’data)” to use them on calculations but i can’t save the data on the matrix, it would be very helpfull if someone can tellme what to do, thanks.

Freddy replied on : 87 of 95

Hi,

I have a problem in property editor, i have to define X axis label as ω, can you help me?

martin replied on : 88 of 95

Hi,

I want use uitable, and uitable should present matrix named for example a. I need insert numbers ” 1, 2, 3,…” and strings “a, b,c,….” to the table.

At the end I need result b=a*a.

PS:

Here is example in M-file.
i3 = sym(‘i3′,’real’);
a=[ 0 0 i3; 1 2 3];
b=[2 2; 2 2; 2 2];
c=a*b;

martin replied on : 89 of 95

Hi,

I would like automatic create a matrix, or array. My program should work like this:

If I insert any number n, then it will create matrix, or array with elements i1;i2;i3;..in with size nx1.

For example:
if
n=2;
then result is [i1;i2],

ans =

i1
i2

if
n=4;
then result is [i1;i2;i3;i4].

Thank you

Bram replied on : 90 of 95

Hi there,

I was wondering whether it is possible to show a struct in a UItable (or in a GUI, really. But the UItable seems the most likely).

My push-button runs another script which returns quite a big structs, with many embedded structs in them. The whole thing is just a 1X1 struct though. I’d like to view this struct in my GUI just as I can view it in the variable editor. Is this possible?

MASSIVE thanks :)
Bram

Esben replied on : 91 of 95

in # 32 (in 2009) Ken said that they are working on letting the user control alignment… it seems that this is still not implemented?
Any solution suggestions?

Nimrod replied on : 92 of 95

I use the GUIDE option and placed a table.
The table size is 4×6.
I want to have it 1×6 -> I tried to delete the extra rows with no success.
It keep on returning them when I press Apply/OK

scott replied on : 94 of 95

I have a uitable with a popupmenu. I have a selection in the popupmenu titled “User Defined” which if selected opens a uigetfile dialog box that I retrieve a file name from to be added to the popupmenu selection list. My problem is that I want the popupmenu selection to be the new filename I added to the popupmenu list insted of the “User Defined” selection. How can I set the value of the popupmenu to reflect this?
Here is my code:
function Curves_uitable_CellEditCallback(hObject, eventdata, handles)
Cdata = get(hObject,’Data’);
if strcmp(Cdata(1,1),’User Defined’)

[FileName,PathName] = uigetfile(‘*’);
FilePath = fullfile(PathName,FileName);
if isequal(FileName,0)
return
end
[pathstr, name, ext] = fileparts(FilePath);
GGmaxCurvesList{end+1} = name;
set(handles.Curves_uitable,’ColumnFormat’,{GGmaxCurvesList});

end

omar replied on : 95 of 95

I have a [16×2 cell array] and I want to now how to call data from column 1 and 2
I mean which one is teh code in order to make it work in a push botton please help me