sách gpt4 ai đã đi

matlab - 如何将元胞数组附加到 .txt 文件?

In lại 作者:行者123 更新时间:2023-12-04 06:38:40 hai mươi bốn 4
mua khóa gpt4 Nike

我之前咨询过including matrices and strings in a .txt file .我现在需要将单元格附加到它。从我之前的问题:

str = 'This is the matrix: ';
mat1 = [23 46; 56 67];
fName = 'output.txt';
fid = fopen(fName, 'w');
if fid >= 0
fprintf(fid, '%s\n', str);
fclose(fid);
kết thúc
dlmwrite(fName, mat1, '-append', 'newline', 'pc', 'delimiter', '\t');

现在我想附加一个字符串:'删除的标识符是',然后在它下面添加这个元胞数组:
'ABC' [10011] [2]
'DEF' [10023] [1]

一些相关链接:

http://www.mathworks.com/help/techdoc/ref/fileformats.html , http://www.mathworks.com/support/solutions/en/data/1-1CCMDO/index.html?solution=1-1CCMDO

1 Câu trả lời

不幸的是,你不能使用像 DLMWRITE 这样的函数。或 CSVWRITE用于写入数据元胞数组。但是,要获得您想要的输出,您仍然可以使用一次对 FPRINTF 的调用。 ,但您必须指定元胞数组一行中所有条目的格式。建于 my answer to your previous question ,您将添加这些额外的行:

str = 'The removed identifiers are: '; %# Your new string
cMat = {'ABC' 10011 2; 'DEF' 10023 1}; %# Your cell array
fid = fopen(fName,'a'); %# Open the file for appending
fprintf(fid,'%s\r\n',str); %# Print the string
cMat = cMat.'; %'# Transpose cMat
fprintf(fid,'%s\t%d\t%d\r\n',cMat{:}); %# Print the cell data
fclose(fid); %# Close the file

新文件内容(包括旧示例)将如下所示:
This is the matrix: 
23 46
56 67
The removed identifiers are:
ABC 10011 2
DEF 10023 1

关于matlab - 如何将元胞数组附加到 .txt 文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4564955/

hai mươi bốn 4 0
Bài viết được đề xuất: php - PHP 中的成本,读取 XML 比列出文件夹中的文件值得吗?
Bài viết được đề xuất: java - 绘制东西时用鼠标移动时滞后
Bài viết được đề xuất: uikit - Tương tác Core Graphics và UIKit
Bài viết được đề xuất: java - Richfaces 日历 "ü"(ü) 字符问题
行者123
Hồ sơ cá nhân

Tôi là một lập trình viên xuất sắc, rất giỏi!

Nhận phiếu giảm giá Didi Taxi miễn phí
Mã giảm giá Didi Taxi
Giấy chứng nhận ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com