Hi there I’m currently trying to find a way to save 2 variables from my workspace into a file. I want the file name to be put together using the original and the current date.
I only want the max value from the variables so:
max(streaking)
and
max(tap_total)
The original file name is:
3_FM001_02_05460$BandP$64_24000_FWD_1x1_PRI_PRI_PRI_PRI_15_17_ActivePixelMeans.csv
The only portion of this original file name that I would like to use is:
3_FM001_02_05460$BandP$64_24000_FWD_1x1
These can be saved in a text file or spreadsheet, it doesnt matter.
An example of the new file name would be something like this:
3_FM001_02_05460$BandP$64_24000_FWD_1x1_7-26-2012
Also,
If something could be done in the file to display which variable is which, for example:
Streaking: 1.272 % this would come from the variable max(streaking)
Tap_Total: 2.252 % this would come from the varaible max(tap_total)
EDIT:
% Construct a questdlg with three options
choice = questdlg('Would you like to save?', ...
'Save Options', ...
'Yes','No','Cancel','Cancel');
% Handle response
switch choice
case 'Yes'
disp([choice ' processing.'])
save_option = 1;
case 'No'
disp([choice ' processing.'])
save_option = 0;
case 'Cancel'
disp('Canceled.')
save_option = 2;
end
file_to_get = evalin( 'base', 'file_to_get' );
streaking = evalin( 'base', 'streaking' );
tap_total = evalin( 'base', 'tap_total' );
if save_option == 0
elseif save_option == 1
max_streak = max(streaking);
max_tap = max(tap_total);
str_streak = mat2str(max_streak);
str_tap = mat2str(max_tap);
fname = file_to_get;
pruned_fname = regexprep(fname,'_PRI(\w*).(\w*)','');
new_fname = [pruned_fname '_' date '.csv'];
path1 = '\\pfile01thn\bbruffey$\My Documents\analysis data\Banding and Streaking Results';
fid = fopen([path1 new_fname], 'w');
fprintf(fid,['Max Banding: %s\nMax Streaking: %s'],str_tap,str_streak)
fclose(fid);
elseif save_option == 2
end
This would be a great place to use the
regexprepcommand to prune the original filename down.Example:
Now, a note about the
regexprepcommand I used here. This is specific for the filename you provided here. Since it looks like you want to trim off everything after the the first_PRII used a tag(\w*)which means any combination of[a-z A-Z _ 0-9]can follow. Notice that since this is a filename there is a.there hence why I added a period in and followed that with another(\w*)to finish out the csv. You can find more info on these sorts of operators here.Now that you have the
pruned_fnameyou can simply add whatever you want to it. So if you want to add the date in with an underscore to space it just simply do something like this:Now you simply need to open the file to write to it. you might need to append the path to where you want to save it, I’m just going to call it
pathfor now. It would be something likeC:\Documents\Now with the
fidyou have the id of the file you want to write to. This should be a new file and if it isn’t you are going to overwrite the file contents if you do it this way. Just be aware =)Next you can simply write those first two lines to the file using
fwritefprintf, just to name a few possible functions.Hopefully that’ll get you setup there!