Matlab:关于dataset()的问题 [英] Matlab: Question regarding 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屋!