2
votes

I'm not able to create a table from a dataset using the uitable in matlab and I need help! Here's the problem:

I created a simple dataset :

names = {'John'; 'Henri'}
ages = [26; 18];
d1 = dataset({names, 'Name'}, {ages, 'Age'})

then I'have tried to create a uitable with this data and I wrote this line

uitable('data',double(d1))

but I received this error message:

??? Error using ==> uitable
Data must be a numeric, logical, or cell array

Error in ==> uitable at 56
        thandle = builtin('uitable', varargin{:});

So I tried again with

uitable('data',cellstr(d1))

but I got this error:

??? Error using ==> dataset.cellstr at 32
Error when converting 'Age' to cell array of strings.

Caused by:
    Error using ==> cellstr at 34
    Input must be a string.

I can not understand how I can create a uitable from a dataset with both numeric and strings entries.

Would someone be so kind as to help me?

1

1 Answers

2
votes

The errors are because you are using the uitable incorrectly. Here's a minimal example that illustrates how to do it.

dataCell={'John',26;'Henri',18};%# store data as a cell
colNames={'Name','Age'};%# names for each column of data

uitable('Data',dataCell,'ColumnName',colNames);

This should give you a neat table that looks like this

enter image description here

EDIT

To answer your comment below, if you are creating your dataset from a cell and an array as in your example, then you can directly combine both into a cell as

dataCell=[names,num2cell(ages)];

and proceed as above. If you already have d1 as a dataset, perhaps not created by you, then you can create a uitable from that as

uitable('Data',[d1.Name,d1.Age])