create variable name and save

1 回表示 (過去 30 日間)
MiauMiau
MiauMiau 2015 年 5 月 13 日
編集済み: Stephen23 2023 年 9 月 12 日
Hi
I work with several subjects, and I want to find a way to 1. May a new folder for each one of them (with their name and timestamp) 2. Store the matfile in the folder again under their name
Obviously I want to change names of the folder and the matfile not to often.
So far I have in mind something as the following code:
str = date;
Name_Folder = strcat('Personx_', str); %Folder name
mkdir(Name_Folder)
Name_File = 'Personx_TrialOne'; % Name of matfile
Personx_TrialOne = 5; % ??
save(strcat('./',Name_Folder,'/',Name_File), Name_File);
But I don't see how I can save a value in "Personx_TrialOne" without having to type "Personx_TrialOne" explicitly (but by using Name_File for instance, such that for each person only this line would be changed. Hence something as in Name_File = 5 basically)

採用された回答

Stephen23
Stephen23 2015 年 5 月 13 日
編集済み: Stephen23 2015 年 5 月 13 日
  • Instead of concatenating file-paths together, you should use fullfile.
  • sprintf can be used to generate the filename using some sequential integers.
  • mkdir can be used to create a new directory.
  • You can get the current date+time using clock, and convert this using datestr.
>> nameFolder = sprintf('Personx_%s',datestr(clock,'yyyymmdd'))
nameFolder =
Personx_20150513
>> trialNumber = 5;
>> nameFile = sprintf('PersonTrial_%i.mat',trialNumber)
nameFile =
PersonTrial_5.mat
>> namePath = fullfile(nameFolder,nameFile)
namePath =
Personx_20150513\PersonTrial_5.mat
>> save(namePath,...names of variables here!)
If you really want to automatically generate the words 'one', 'two', 'three', etc, for each trial, then you can use my FEX submission num2words:
  3 件のコメント
MiauMiau
MiauMiau 2015 年 5 月 13 日
Edit: I found it, what I was basically looking for was the eval function! many thanks nevertheless
Stephen23
Stephen23 2015 年 5 月 14 日
編集済み: Stephen23 2023 年 9 月 12 日

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCalendar についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by