0
votes

I have a function in matlab.

function [MEAN STD]=result(data)
MEAN=mean(data);
STD=std(data);

savefilename=sprintf('%s',data)
save(savefilename,'MEAN','STD')
end

i set data's filename=ET1_A_l1(imported to workspace alrdy)(ET1_A_l1=[1;2;1;3;1;4] to find the mean and std of selected data(ET1_A_l1),and save the statistical feature into .mat form as shown in below:

>>[MEAN STD]=result(ET1_A_l1)

As a result, the name of save file is 121314.mat,and it is not 'ET1_A_l1',is there any good idea of using MATLAB's efficient code to change the filename correctly?

Thanks

1
What is your function, and how is it called? It looks quite mixed up in your question... - glglgl
i edit the function again but stil cannot save the correct name file .. - Tony YEe

1 Answers

1
votes

If I understand correctly, you can use inputname, which gives you the name of the function argument in the callers workspace:

function result(data)
    display(['file name should be ' inputname(1)]);  % name of the first parameter
end

...

>> result(ET1_A_l1);
file name should be ET1_A_l1