在向量的情况下为xlswrite

编程入门 行业动态 更新时间:2024-10-10 13:20:11
本文介绍了在向量的情况下为xlswrite的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我有一个.mat文件,其中包含 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

本文发布于:2023-10-29 00:28:46,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1538197.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:向量   情况下   xlswrite

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!