最快的方式导出2d矩阵到三元组格式CSV文件在Matlab [英] Fastest way to export a 2d matrix to a triples format CSV file in Matlab

查看:162
本文介绍了最快的方式导出2d矩阵到三元组格式CSV文件在Matlab的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想转换2d矩阵,例如:

  10 2 
3 5

到(row,col,value)CSV文件,例如:

  1,1,10 
1,2,2
2,1,3
2,2,5

h2_lin>解决方案

我没有找到一个单一的命令,但尝试下面的代码:

  [i1,i2] = ind2sub(size(A),1:numel(A)); 
csvwrite('test.csv',[i2',i1',reshape(A',numel(A),1)]);

输出为:

  type test.csv 

1,1,10
1,2,2
2,1,3
2,2, 5


I want to convert a 2d matrix, for example:

10  2
3   5

to a (row,col,value) CSV file, for example:

1,1,10
1,2,2
2,1,3
2,2,5

is it possible to do it in a single Matlab command?

解决方案

I didn't find a way with a single command, but try the following code:

[i1,i2] = ind2sub(size(A),1:numel(A));
csvwrite('test.csv',[i2',i1',reshape(A',numel(A),1)]);

The output is:

type test.csv

1,1,10
1,2,2
2,1,3
2,2,5

这篇关于最快的方式导出2d矩阵到三元组格式CSV文件在Matlab的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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