Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个矩阵
a=[1 2; 3 4; 5 6];
在 MatLAB 中,我想将其导出到格式为{1,2},{3,4},{5,6}. 我怎样才能做到这一点?我需要使用低级 I/O 吗?
{1,2},{3,4},{5,6}
你可以使用fprintf如下:
fprintf
a=[1 2; 3 4; 5 6]; file_id=fopen('output.txt','w'); [m,n]=size(a); for i=1:m-1 fprintf(file_id,'{%d,%d},',a(i,1),a(i,2)); end fprintf(file_id,'{%d,%d}',a(m,1),a(m,2)); fclose(file_id)