在向量的情况下为xlswrite [英] xlswrite in case of vectors
问题描述
titles = {'time','data'}
和2列向量: time = [1; 2; 3; 4; 5]
和 data = [10; 20; 30; 40; 50]
我创建了一个名为table = {'time','data';时间数据}的新单元,我使用: xlswrite(文件名,表);
但是,当我打开xlsx文件时,它只显示标题,不显示数字。
我看到xlswrite将显示空单元格,以防我尝试在单元格中导出多个数字。
有什么我可以做的来导出整个向量而不是在它的单元格中写入每个值?
我试图得到的最终结果是这样的:
时间数据
1 10
2 20
3 30
4 40
5 50
你有几个选项。通常我做的是将它分成两个 xlswrite
调用,一个用于标题,另一个用于数据。
titles = {'time','data'};
time = [1; 2; 3; 4; 5];
data = [10; 20; 30; 40; 50];
xlswrite('myfile.xlsx',标题'Sheet1','A1');
xlswrite('myfile.xlsx',[时间,数据],'Sheet1','A2');
或者,如果您有R2013b或更新版本,还可以使用 表
内置,它的自己写出数据的方法。使用相同的样本数据:
mytable = table(time,data,'VariableNames',titles);
writetable(mytable,'myfile.xlsx');
I have a .mat file which contains titles={'time','data'}
and 2 column vectors:
time=[1;2;3;4;5]
and data=[10;20;30;40;50]
.
I created a new cell called table={'time','data';time data} and i used:
xlswrite(filename,table);
However, when i open the xlsx file it shows me only the titles and not showing the numbers. I saw that xlswrite will show empty cell in case im trying to export more than 1 number in a cell.
Is there anything i can do to export the whole vector instead of writing each value in it's cell?
The final result that i tried to get is like this:
time data
1 10
2 20
3 30
4 40
5 50
You have a couple options. Usually what I do is break it into two xlswrite
calls, one for the header and one for the data.
titles = {'time','data'};
time = [1;2;3;4;5];
data = [10;20;30;40;50];
xlswrite('myfile.xlsx', titles, 'Sheet1', 'A1');
xlswrite('myfile.xlsx', [time, data], 'Sheet1', 'A2');
Alternatively, if you have R2013b or newer you can also use the table
builtin, which has its own method for writing out data. With the same sample data:
mytable = table(time, data, 'VariableNames', titles);
writetable(mytable, 'myfile.xlsx');
这篇关于在向量的情况下为xlswrite的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!