Matlab:关于dataset()的问题 [英] Matlab: Question regarding dataset()

查看:1518
本文介绍了Matlab:关于dataset()的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的工作空间中有大约50个元素(1列字符数组)。有没有办法将所有这些元素放在一个单独的数据集中,而不明确地对每个数据集进行处理。我有一个变量x,它列出所有的元素名称。我已经尝试了很多东西,但似乎没有任何效果。在这种情况下,dataset()的帮助也没有帮助。希望有人可以帮助我这个最后的障碍,然后才能看到一些结果。

解决方案

如果我理解正确,你有50您的工作区中的变量,其所有名称存储在变量 x (我认为是一个50元素的单元格数组)。以下示例(仅包含3个变量)说明了如何将一组变量组合成一个数据集

 >> var1 = ['a'; 'b' 'C']; %#一个3乘1个字符数组
>> var2 = ['d'; 'e' 'F']; %#一个3乘1个字符数组
>> var3 = ['g' 'H'; '一世']; %#一个3乘1个字符数组
>> x = {'var1'; 'var2'; 'var3'}; %#3-by-1单元格数组中的变量名称
>> varData = cellfun(@ eval,x,'UniformOutput',false)%#在单元格数组
>>中收集变量数据
%# data = num2cell([varData x],2); %#将变量数据与
%#变量名合并,并在另外的单元格数组
>>中收集每对
%# ds = dataset(data {:})%#将数据以逗号分隔的列表形式传递给数据集

ds =

var1 var2 var3
adg
beh
cfi


I have around 50 elements (1 column char array) in my workspace. Is there any way to put all these elements into a single dataset without addressing each one explicitly. I have a variable x, which lists all the element names. I've already tried lots of things but nothing seems to work. The help for dataset() is also not helpful in this case. Hopefully somebody can help me with this final obstacle before I may finally see some results.

解决方案

If I understand correctly, you have 50 variables in your workspace, all the names of which are stored in a variable x (which I presume is a 50-element cell array). The following example (with just 3 variables) illustrates how to get a set of variables into one dataset:

>> var1 = ['a'; 'b'; 'c'];        %# A 3-by-1 character array
>> var2 = ['d'; 'e'; 'f'];        %# A 3-by-1 character array
>> var3 = ['g'; 'h'; 'i'];        %# A 3-by-1 character array
>> x = {'var1'; 'var2'; 'var3'};  %# The variable names in a 3-by-1 cell array
>> varData = cellfun(@eval,x,'UniformOutput',false)  %# Collect the variable data
                                                     %#   in a cell array
>> data = num2cell([varData x],2);  %# Combine the variable data with the
                                    %#   variable names and collect each pair
                                    %#   in an additional cell array
>> ds = dataset(data{:})  %# Pass the data to dataset as a comma separated list

ds = 

    var1    var2    var3
    a       d       g   
    b       e       h   
    c       f       i   

这篇关于Matlab:关于dataset()的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆