Save workspace to a specific folder using regular expression

5 vues (au cours des 30 derniers jours)
10B
10B le 4 Déc 2015
Commenté : 10B le 4 Déc 2015
Hello Community,
Im having difficulties with hopefully a simple problem. I have a scripted workflow and at a certain point, I would like to automate the saving of the workspace contents ie variables created etc. to a specific folder that I make earlier in the script. I also want the saved '.m' file to be named after a part of the original image filename that is used in this processing.
I have a line of code that saves to the current folder, but it doesn't save to the location I want, or take the file name I want:
>> save(regexp('defaultFileName','(?<=IMG_)\d+', 'match', 'once'));
The contents of defaultFileName would be similar to: C:\Users\10B\Matlab\Files\Images\*.* , and from an earlier question I asked, I know '(?<=IMG_)\d+', 'match', 'once')' should work for the regular expression element, but no joy.
There is also a variable called new folder, created via:
newfolder = regexpi(baseFileName, '(?<=IMG_)\d+', 'match', 'once');
newfullpath = fullfile(pwd, newfolder);
mkdir(newfullpath);
that makes the folder I want to save the workspace to, and this folder takes the correct name.
So, how can I replicate saving the workspace to the newly created folder, and taking the parsed name from the image name?
Thanks in advance...

Réponse acceptée

Thorsten
Thorsten le 4 Déc 2015
Modifié(e) : Thorsten le 4 Déc 2015
imagename = ... %whatever you use to extract the imagename
filename = [imagename '.mat'];
save(fullfile(newfullpath, filename))
  1 commentaire
10B
10B le 4 Déc 2015
Thorsten - excellent thank you! This works perfectly.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Debugging and Analysis dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by