MATLAB Answers


Create a data and save a filename automatically

Asked by YEE
on 23 Nov 2012

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, 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?


  1 Comment

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



1 Answer

Answer by Walter Roberson
on 23 Nov 2012


% savefilename='savefile.mat' 
% save(savefilename)
on 23 Nov 2012

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?

Join the 15-year community celebration.

Play games and win prizes!

Learn more
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!