필터 지우기
필터 지우기

saving matrices to text files

조회 수: 3 (최근 30일)
Grace
Grace 2015년 2월 13일
편집: dpb 2015년 2월 14일
Hello! I was wondering if someone could explain to me how to save variables to a text file? And if they could, also explain to me a bit about the purpose of a text file?
For example if I want to save these variables to a text file, would it be something like this?
x = [2:2:28] y = [3:3:43]
save ('variables.txt', x, y)
thank you for your help!

답변 (1개)

dpb
dpb 2015년 2월 13일
편집: dpb 2015년 2월 14일
"...if I want to save these variables to a text file, would it be something like this?"
save ('variables.txt', x, y)
Nope; that form will save a .mat file which is unformatted, not text. It also won't work because the functional form of the save function must specify the variables to be saved by character strings.
save('variables.txt','x','y','-ascii')
would be the form required.
save/load are far more suited to .mat files than for text; I recommend strongly against it for the purpose. Use csvwrite or one of the multitude of other specific functions for the purpose instead. Use
help iofun
and look through the list for various choices and choose something appropriate to the need at hand.
As for what they're for, if you have need to save data in a form that can be read by humans, that's the logical choice. This can, of course include automated editing or as input to other programs that require text/ASCII files or the like.
However, for simply saving data to be recalled later or for lossless transport between systems stream files (often callled "binary") are far more concise and quicker. For data staying within Matlab then as noted above the .mat file has much to be said for it.

카테고리

Help CenterFile Exchange에서 Data Import and Export에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by