automatic filename saving

hi all, i cant seem to find what im looking for, if you had a simple function such as the one below, is it possible for matlab to automatically detect the file name to save it under?
function help
%user input data which will change each time
A = [1; 2; 3]; B = [1; 3; 3];
%save data
save("filename", A); save("filename", B);
end
is there a line of code which instead of the user specifying the name each time, for matlab to just save it under a different name each time the code is run and for different values of A and B thanks kyle

 Réponse acceptée

Sean de Wolski
Sean de Wolski le 5 Mai 2011

1 vote

for ii = 1:n
fn = sprintf('file_%s.jpg',num2str(ii,%04i')); %jpegs named file_0001.jpg, file_0002.jpg etc.
save(fn,ii)
end

3 commentaires

kyle lyth
kyle lyth le 5 Mai 2011
hi thanks for a speedy reply.. ive been trying to use the code, it will run and save the names once, but if i close down the program or rerun it for different variables then the file names dont continue to increase, as they would for example in a digital camera when taking pictures
Sean de Wolski
Sean de Wolski le 5 Mai 2011
You need to reinitialize your for loop if you want it to start higher.
kyle lyth
kyle lyth le 5 Mai 2011
thanks for your help
name = dir('data_*');
k = size(name);
for ii = (k(1)+1):(k(1)+2)
fn = sprintf('data_%s',num2str(ii,04i')); %jpegs named file_0001.jpg, file_0002.jpg etc.
save(fn,'deflection','int_force','-mat')
end
that was the code i ended up with and it works great thank you

Connectez-vous pour commenter.

Plus de réponses (0)

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by