从数据集创建合适的

发布于 2024-11-03 21:20:09 字数 829 浏览 4 评论 0原文

我无法使用 matlab 中的 uitable 从数据集创建表,我需要帮助!问题是:

我创建了一个简单的数据集:

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

然后我尝试使用这些数据创建一个数据集,我写了这一行,

uitable('data',double(d1))

但收到​​了此错误消息:

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

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

所以我再次尝试,

uitable('data',cellstr(d1))

但收到此错误:

??? 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'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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

向日葵 2024-11-10 21:20:09

这些错误是因为您使用的是 uitable 错误。这是一个说明如何执行此操作的最小示例。

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

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

这应该会给你一个整洁的表格,看起来像这样

在此处输入图像描述

编辑

来回答你的问题在下面的评论中,如果您像示例中那样从单元格和数组创建数据集,那么您可以直接将两者组合到单元格中

dataCell=[names,num2cell(ages)];

,并按照上面的步骤进行。如果您已经将 d1 作为数据集(可能不是由您创建的),那么您可以从中创建一个 uitable 作为

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

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])
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文