Create a data and save a filename automatically

I have a function in matlab.For ex,
%function [mean std]=size(data,channel)
i set data's filename=ET1_A(imported to workspace alrdy) and channel=2 (total no.channel=63), to find the mean and std of selected data(ET1_A),and I want to save the statistical feature into .mat form in the workspace as shown in below:
%savefile='ET1_A_stat.mat'; save(savefile,'mean','std')
However,if i choose another data like ET1_B,I need to change my code manually like: %savefile='ET1_B_stat.mat'; save(savefile,'mean','std')
Is there any good idea of using MATLAB's efficient code to change the filename automatically nicely?
Thanks

댓글 수: 1

Don't use size() for the name of your function or you'll blow away the built in size() function.

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

답변 (1개)

Walter Roberson
Walter Roberson 2012년 11월 23일

0 개 추천

댓글 수: 6

YEE
YEE 2012년 11월 23일
the link u send gives guidance for how to load the sequence of files,I need to know how to save the filename automatically when i input the data into the function..
The techniques used there to construct the file names can be used to construct file names for saving files.
savefile = [filename '_stat.mat'];
save(savefile, 'mean', 'std');
YEE
YEE 2012년 11월 23일
i type the following code in function:
savefile=sprintf('%s_Channel%d',data,channel,); savefilename='savefile.mat' save(savefilename) the results was a 'savefile.mat' saved only..how to change the filename to ET1_A
The results was a 'savefile.mat'data saved only..how to change the filename to ET1_A_1??
savefile=sprintf('%s_Channel%d.mat',data,channel);
% savefilename='savefile.mat'
% save(savefilename)
save(savefile)
YEE
YEE 2012년 11월 23일
편집: YEE 2012년 11월 23일
let says the matrix ET1_A_l1=[1;2;1;3;1;4],channel=1 i run your code and the save file name is '1_Channel12_Channel13_Channel14.mat',how to make the data can be named to be ET1_A_l1??
DO you have a variable which would have the string 'ET1_A_I1' stored in it at that point? If you are loading files in a loop, then how did you figure out which file to load?

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

카테고리

도움말 센터File Exchange에서 File Operations에 대해 자세히 알아보기

제품

태그

질문:

YEE
2012년 11월 23일

Community Treasure Hunt

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

Start Hunting!

Translated by