Saving a variable to a continuously changing file name
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Calabrese
le 27 Juil 2015
Commenté : Calabrese
le 30 Juil 2015
I would like to save a variable to a file/filename that relates to a previously loaded filename and repeat the code with a new file and save the variable to a different filename.
First I load in a file of choice
data = uigetfile('*.csv');
IP_Testing = xlsread(data)
example: BurnIn_2ndary_volt_curr_columnar_20150527_1940_IAM002.csv
Note: The datetime is in the filename
Then I reduce the file to a small matrix from data that I selected with the brushing tool. I assign that matrix to a variable.
details = [mean(IAMHS(:,2)) std(IAMHS(:,2)) min(IAMHS(:,2)) max(IAMHS(:,2));...
mean(CMP1(:,2)) std(CMP1(:,2)) min(CMP1(:,2)) max(CMP1(:,2));...
mean(CMP2(:,2)) std(CMP2(:,2)) min(CMP2(:,2)) max(CMP2(:,2));...
mean(PDU_OP(:,2)) std(PDU_OP(:,2)) min(PDU_OP(:,2)) max(PDU_OP(:,2));...
mean(ThreePThreeV(:,2)) std(ThreePThreeV(:,2)) min(ThreePThreeV(:,2)) max(ThreePThreeV(:,2));...
mean(TenV_PREF(:,2)) std(TenV_PREF(:,2)) min(TenV_PREF(:,2)) max(TenV_PREF(:,2));...
mean(TenV_REF(:,2)) std(TenV_REF(:,2)) min(TenV_REF(:,2)) max(TenV_REF(:,2))];
Now I would like to save the matrix (details) to a file name that relates to the previous loaded file (same datetime).
Examples: BurnIn_2ndary_20150527_1940.mat
-------------------------------------------------------------------------------------------------------------
The problem is I will run my code to retrieve another file similar to the first one I imported (different datetime).
Example: BurnIn_2ndary_volt_curr_columnar_20150528_1500_IAM002.csv
In the end I would like to save it to a similar name
Examples: BurnIn_2ndary_20150528_1500.mat
So I need my code that saves the file to be able to recognize a different file so that I can save it to a different filename. Being able to hold on to the datetime in the name is important for later plotting all of the new files I have saved
0 commentaires
Réponse acceptée
Walter Roberson
le 27 Juil 2015
You can use regexp() to extract portions of the name. For example,
regexp(filename, '\d+_\d+', 'match')
should extract the data and time substring.
The first part looks to be
regexp(filename,'^[A-Za-z0-9]+_[A-Za-z0-9]+', 'match')
11 commentaires
Walter Roberson
le 27 Juil 2015
Simplified version that does it all in one, producing a character string:
regexprep(filename,{'(?<=^[^_]+_[^_]+_)[^0-9]+','_[^_]+\.csv$'}, '')
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Data Type Conversion dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!