用于数据Matlab的字符串标题 [英] String Header for data Matlab

查看:358
本文介绍了用于数据Matlab的字符串标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现在Matlab中为矩阵添加标题问题这与我所需要做的非常接近。我希望能够保留数据在单元格中,因为我的头文件很大,而且我多次运行这个文件,我不想使用文件i.o.因为它增加了很多时间。

I found "Adding a header to a matrix in Matlab" question which was very close to what I need done. I was hoping to keep the data in the cells, since my headers are large and i'm running this multiple times I dont want to use file i.o. since it adds tons of time.

这就是我所拥有的...

this is what i have...


  • header =('Quarter','每月剩余金额','年度剩余金额');

    data =

  • header = ( 'Quarter', 'monthly amount remaining', 'annual amountremaining');

data   =  


1 30000 150000 2 20000 130000

t似乎得到这个

and i can't seem to get this

非常令人沮丧,我试过num2str ,还有一堆其他的东西......我要去尝试num2cell,然后制作一个大数组并填充它们......很高兴星期五,我回家了T_T

out = Quarter monthly am annual am 1 30000 150000 2 20000 130000

.html>数据集数组

If you have access to the Statistics Toolbox, you can create a dataset array

header = {'Quarter', 'monthly amount remaining', 'annual amountremaining'}
data =    [ 1        30000    150000;
    2        20000    130000];

ds = dataset({data,header{:}})

ds = 

    Quarter    monthlyAmountRemaining    annualAmountremaining
    1          30000                     1.5e+05              
    2          20000                     1.3e+05  

请注意,这将删除标题中的空格名称,但是对于数据集,则可以使用这些名称方便地访问列,例如:

Note that this removes the spaces in your header names, but with the dataset, you can then use these names to conveniently access the columns, such as:

>> ds.Quarter

ans =

     1
     2

如果您只想写入Excel(并且不使用数据集方法),则可以创建单个单元格数组:

If you just want to write to Excel (and not use the dataset methods), you can create a single cell array:

 [header;num2cell(data)]

ans = 

    'Quarter'    'monthly amount remaining'    'annual amountremaining'
    [      1]    [                   30000]    [                150000]
    [      2]    [                   20000]    [                130000]

这篇关于用于数据Matlab的字符串标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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