How to Save a File with a New Exetesion?

조회 수: 14 (최근 30일)
Rightia Rollmann
Rightia Rollmann 2017년 3월 16일
댓글: Jan 2017년 3월 16일
Imagine I have the variable below:
B = [1 2 3];
save(B, B);
When I save variable B, MATLAB creates a file named B.mat. Is there any way to replace its extension with another word (e.g., B.FFF)? I want to do it to be able to find and sort files with such extension easier.

채택된 답변

Adam
Adam 2017년 3월 16일
편집: Adam 2017년 3월 16일
The obvious
save( 'B.fff', 'B' );
works fine (though obviously better with a full path as always), but as John points out, loading this in the standard way will not work, though
load( 'B.fff', '-mat' )
will do. I have done this myself (though with more meaningful extensions!) on a few occasions for saving data files for a user where it isn't important to the user what type of file it is and I prefer to give my own extension to define the 'type' of file as people sometimes do with XML files.
Purely from a point of view of loading and saving in Matlab there is no obvious reason to not use .mat, it's just a preference for me for files a user will interact with - e.g. if they have 3 different files for parameters of different things then I like to give each an extension related to the type of parameters they store.
  댓글 수: 1
Jan
Jan 2017년 3월 16일
+1. Exactly. You cal load e.g. .fig-files using this method also.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

John D'Errico
John D'Errico 2017년 3월 16일
Well, I suppose you could try. But then MATLAB would be unable to access that file, since it needs to be a .mat file. If the extension is not .mat, then MATLAB will assume the file is saved as a simple ascii text file.
Better is to put the tag into the name. B_FFF, or FFF_B. The latter is better, since a simple sort will bring all those names together, just as you wish.

카테고리

Help CenterFile Exchange에서 Environment and Settings에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by