MATLAB保存数据方法Word文档下载推荐.docx

上传人:b****4 文档编号:16048778 上传时间:2022-11-17 格式:DOCX 页数:15 大小:23.33KB
下载 相关 举报
MATLAB保存数据方法Word文档下载推荐.docx_第1页
第1页 / 共15页
MATLAB保存数据方法Word文档下载推荐.docx_第2页
第2页 / 共15页
MATLAB保存数据方法Word文档下载推荐.docx_第3页
第3页 / 共15页
MATLAB保存数据方法Word文档下载推荐.docx_第4页
第4页 / 共15页
MATLAB保存数据方法Word文档下载推荐.docx_第5页
第5页 / 共15页
点击查看更多>>
下载资源
资源描述

MATLAB保存数据方法Word文档下载推荐.docx

《MATLAB保存数据方法Word文档下载推荐.docx》由会员分享,可在线阅读,更多相关《MATLAB保存数据方法Word文档下载推荐.docx(15页珍藏版)》请在冰豆网上搜索。

MATLAB保存数据方法Word文档下载推荐.docx

savedata'

num2str(i)])

end

使用eval

若i不为整数,改换i即可

上述为保存至分开的mat数据当中

如果要一次保存至一个mat当中,可以直接使用save

save('

filename'

'

data1'

data2'

-ascii'

-append'

) 

filename.mat'

save(['

file_'

num2str(i),'

.mat'

],myvar)

10%%%succeed

a=i;

F12=['

FILE_'

.dat'

];

save(F12,'

a'

);

Valueof 

fmt

FileFormat

'

-mat'

BinaryMAT-fileformat.

Textformatwith8digitsofprecision.

-tabs'

Tab-delimitedtextformatwith8digitsofprecision.

-double'

Textformatwith16digitsofprecision.

Tab-delimitedtextformatwith16digitsofprecision.

Ref:

比如:

A=[123

456]

fid=fopen('

D1.txt'

wt'

fprintf(fid,'

%d%d%d'

\n'

A'

fclose(fid);

一:

存txt文件,用dlmwrite()dlmwrite

将一个矩阵写到由分隔符分割的文件中。

在保存整数到文件时使用save存为ascii文件时,常常是文件里都是实型格式的数据(有小数点,和后面很多的0,看着很不方便)。

于是要保存此类数据时,我们可以使用此dlmwrite命令。

使用方法:

dlmwrite('

M)

使用默认分隔符“,”将矩阵M写入文本文件filename中;

M,'

D'

使用分隔符D分割数据,“\t”表示tab分割,“,”为默认分割符;

R,C)

从矩阵M的第R行、第C列开始,作为要写矩阵块的左上角,将数据用D分割写入文件。

其他用法有:

attrib1'

value1,'

attrib2'

value2,...)

attribute-valuelist)

例如:

a=[123;

456;

789];

test.txt'

a);

则test.txt中的内容为:

1,2,3

4,5,6

7,8,9

而使用save保存为TXT文件类型:

save'

tst.txt'

a-ascii;

文本文件里的内容为:

1.0000000e+0002.0000000e+0003.0000000e+000

4.0000000e+0005.0000000e+0006.0000000e+000

7.0000000e+0008.0000000e+0009.0000000e+000

而使用save保存为dat文件类型:

save11.data-ascii;

11.dat文件里的内容为:

在循环结构中可利用以下代码:

3%%%%succeed;

filename=['

phi_'

num2str(i),'

.txt'

dlmwrite(filename,a);

result:

1.txt,2.txt,3.txt;

利用cswrite函数保存成dat类型。

m=[3691215;

510152025;

714212835;

1122334455];

csvwrite('

csvlist.dat'

m);

3,6,9,12,15

5,10,15,20,25

7,14,21,28,35

11,22,33,44,55

二.利用xlswrite函数,保存为excel文件类型;

xlswrite(filename,M)

xlswrite(filename,M,sheet)

xlswrite(filename,M,range)

xlswrite(filename,M,sheet,range)

status=xlswrite(filename,...)

[status,message]=xlswrite(filename,...)

xlswritefilenameMsheetrange

Description

xlswrite(filename,M)writesmatrixMtotheExcel?

filefilename.Thefilenameinputisastringenclosedinsinglequotes.TheinputmatrixMisanm-by-nnumeric,character,orcellarray,wherem<

65536andn<

256.Thematrixdataiswrittentothefirstworksheetinthefile,startingatcellA1.

example:

Example1—WritingNumericDatatotheDefaultWorksheet

Writea7-elementvectortoMicrosoftExcelfiletestdata.xls.Bydefault,thedataiswrittentocellsA1throughG1inthefirstworksheetinthefile:

xlswrite('

testdata'

[12.75.02-9863.90-.256])

Example2—WritingMixedDatatoaSpecificWorksheet

Thisexamplewritesthefollowingmixedtextandnumericdatatothefiletempdata.xls:

d={'

Time'

'

Temp'

;

1298;

1399;

1497};

Callxlswrite,specifyingtheworksheetlabeledTemperatures,andtheregionwithintheworksheettowritethedatato.The4-by-2matrixwillbewrittentotherectangularregionthatstartsatcellE1initsupperleftcorner:

s=xlswrite('

tempdata.xls'

d,'

Temperatures'

E1'

s=

1

Theoutputstatussshowsthatthewriteoperationsucceeded.Thedataappearsasshownhereintheoutputfile:

TimeTemp

1298

1399

1497

Example3—AppendingaNewWorksheettotheFile

Nowwritethesamedatatoaworksheetthatdoesn'

tyetexistintempdata.xls.Inthiscase,MATLABappendsanewsheettotheworkbook,callingitbythenameyousuppliedinthesheetsinputargument,'

NewTemp'

.MATLABdisplaysawarningindicatingthatithasaddedanewworksheettothefile:

Warning:

Addedspecifiedworksheet.

Ifyoudon'

twanttoseethesewarnings,youcanturnthemoffusingthecommandindicatedinthemessageabove:

warningoffMATLAB:

xlswrite:

AddSheet

Nowtrythecommandagain,thistimecreatinganothernewworksheet,NewTemp2.Althoughthemessageisnotdisplayedthistime,youcanstillretrieveitanditsidentifierfromthesecondoutputargument,m:

[statmsg]=xlswrite('

NewTemp2'

msg

msg=

message:

'

Addedspecifiedworksheet.'

identifier:

MATLAB:

AddSheet'

在循环结构中;

3%%%

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 农林牧渔 > 林学

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1