vactor表到普通表的提取

vactor表到普通表的提取

本文介绍了Matlab vactor表到普通表的提取的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个表名output,其中包含这样的尺寸:

I have a table name output which contains the dimention like this:

cat values s1 s2 sub_cat 1 [1x2 double] 0.66584 3.1383 {2x1 cell}

cat values s1 s2 sub_cat 1 [1x2 double] 0.66584 3.1383 {2x1 cell}

值例如:
cat values s1 s2 sub_cat
1 2.5 3.4 0.555 3.999 emozi-1 emozi-32 2.9 7.1 5.0 2 khazal-11 kha-9

values are such as:
cat values s1 s2 sub_cat
1 2.5 3.4 0.555 3.999 emozi-1 emozi-32 2.9 7.1 5.0 2 khazal-11 kha-9

我如何像这样重新排列此表(将向量删除为正常值):

How can i re-arrange this table like this(remove vector to normal):

cat values s1 s2 sub-cat1 2.5 0.555 3.999 emozi-11 3.4 0.555 3.999 emozi-32 2.9 5.0 2 khazal-112 7.1 5.0 2 kha-9

cat values s1 s2 sub-cat1 2.5 0.555 3.999 emozi-11 3.4 0.555 3.999 emozi-32 2.9 5.0 2 khazal-112 7.1 5.0 2 kha-9

任何人都可以帮助在matlab中做到这一点吗?

Can anyone help to do this in matlab?

推荐答案

认为您需要的是表格 stack 操作.这有点棘手,因为我认为您正在尝试同时堆叠两个表变量(不获取所有组合),所以这是我认为您需要的:

I think what you're after is a table stack operation. It's a bit tricky because I think you're trying to stack two table variables simultaneously (without getting all the combinations), so here's what I think you need:

%# Sample table data
t = table([1;2], [1, 2; 3, 4], [0.1; 0.2], {'a', 'b'; 'c', 'd'}, ...
    'VariableNames', {'cat', 'values', 's1', 'sub_cat'});
%# Combine corresponding columns of 'values' and 'sub_cat' so
%# that we've got something we can stack
t2 = table(t.cat, [num2cell(t.values(:,1)), t.sub_cat(:,1)], ...
    [num2cell(t.values(:,2)), t.sub_cat(:,2)], ...
    t.s1, 'VariableNames', {'cat', 'vs1', 'vs2', 's1'});
%# Actually call 'stack'
t3 = stack(t2, {'vs1', 'vs2'});
%# Unpick the variables in 't3' into something more useful
t4 = table(t3.cat, t3.s1, cell2mat(t3.vs1_vs2(:,1)), ...
    t3.vs1_vs2(:,2), 'VariableNames', ...
    {'cat', 's1', 'values', 'sub_cat'})

这篇关于Matlab vactor表到普通表的提取的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-12 11:39