saving a file with help of a function

조회 수: 1 (최근 30일)
Rica
Rica 2014년 11월 11일
댓글: Rica 2014년 11월 11일
Hi! is there any possibilty to change the name of the file to be saved with the input of a function? as an Exemple:
%
[]=myfunction(input1,input2,FileName)
Calculation of X,Y
S=struct('X',X,'Y',Y); % building of a structure
save('FileName','S')
Thank you
  댓글 수: 2
Guillaume
Guillaume 2014년 11월 11일
I'm not sure what you're asking. Doesn't your example do exactly what you want?
Rica
Rica 2014년 11월 11일
편집: Rica 2014년 11월 11일
Hi.
for exemple i call the function myfunction(input1, input2, Resultdata1) and i want that the calculated structure S should be saved in the file Resultdata1.
some thing like this:
%function [ ] = addition( X,Y,filename )
A=X+Y;
S=struct('A',A,'X',X,'Y',Y)
save(filename,'S')
end
Calling the function:
%
addition(1,2,Resultdata1)
addition(5,7,Resultdata2)
..
..
and the tha data should be save in Resultdata1.mat, Resultdata2.mat.......
thank you

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

채택된 답변

the cyclist
the cyclist 2014년 11월 11일
addition(1,2,'Resultdata1.mat')

추가 답변 (1개)

Philipp Maier
Philipp Maier 2014년 11월 11일
The only thing missing in your code is that the name of the file needs to be a string when calling addition . For example:
function addition( X,Y,filename )
A=X+Y;
S=struct('A',A,'X',X,'Y',Y)
save(filename,'S')
end
Call this function as follows:
addition(1,2,'Resultdata1')

카테고리

Help CenterFile Exchange에서 File Operations에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by