Home > vbmeg > functions > job > job_plot_meg_dir > job_plot_meg_save_waveform.m

job_plot_meg_save_waveform

PURPOSE ^

Save waveform data. Invoked by job_plot_meg.

SYNOPSIS ^

function job_plot_meg_save_waveform(inst_id)

DESCRIPTION ^

 Save waveform data. Invoked by job_plot_meg.

 [syntax]
  job_plot_meg_save_waveform(inst_id);

 [history]
 2015/12/11 rhayashi Initial version

 Copyright (C) 2011, ATR All Rights Reserved.
 License : New BSD License(see VBMEG_LICENSE.txt)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function job_plot_meg_save_waveform(inst_id)
0002 % Save waveform data. Invoked by job_plot_meg.
0003 %
0004 % [syntax]
0005 %  job_plot_meg_save_waveform(inst_id);
0006 %
0007 % [history]
0008 % 2015/12/11 rhayashi Initial version
0009 %
0010 % Copyright (C) 2011, ATR All Rights Reserved.
0011 % License : New BSD License(see VBMEG_LICENSE.txt)
0012 
0013 global vbmeg_inst;
0014 if isempty(vbmeg_inst.plotmeg{inst_id}.megfile);
0015     warning('Data file not specified.');
0016     return;
0017 end
0018 
0019 switch(vbmeg_inst.plotmeg{inst_id}.sensor_type)
0020     case 1
0021         sensor_type = 'Magnetometer';
0022     case 2
0023         sensor_type = 'Axial gradiometer';
0024     case 3
0025         sensor_type = 'Planar gradiometer';
0026     case -1
0027         sensor_type = 'Mix';
0028     otherwise
0029         error('Unknown sensor type was detected.');
0030 end
0031 
0032 sensor_name    = vbmeg_inst.plotmeg{inst_id}.selected_sensor_name;
0033 sensor_data    = vbmeg_inst.plotmeg{inst_id}.plotting_timecourse;
0034 sensor_average = mean(vbmeg_inst.plotmeg{inst_id}.plotting_timecourse, 1);
0035 
0036 % Save dialog
0037 [s_dir, s_file] = vb_file_select({'.mat'},'Input save filename',true);
0038 if ~isempty(s_file)
0039     save_file     = fullfile(s_dir, filesep, s_file{1});
0040     save_image_file = strrep(save_file, '.mat', '.png');
0041 
0042     % Confirm overwrite or not
0043     if exist(save_file, 'file') == 2
0044         res = questdlg('File already exists. overwrite?', 'Confirm', 'Yes', 'No', 'Yes');
0045         if strcmpi(res, 'No')
0046             return;
0047         end
0048     end
0049     
0050     % Save waveform and image file
0051     fig = vbmeg_inst.plotmeg{inst_id}.h_fig;
0052     oldscreenunits = get(fig,'Units');
0053     oldpaperunits  = get(fig,'PaperUnits');
0054     oldpaperpos    = get(fig,'PaperPosition');
0055 
0056     set(fig,'Units','pixels');
0057     scrpos = get(fig,'Position');
0058     newpos = scrpos/100;
0059     set(fig,'PaperUnits','inches','PaperPosition',newpos)
0060 
0061     vb_fsave(save_file, 'sensor_name', 'sensor_type', 'sensor_data', 'sensor_average');
0062     print('-dpng', save_image_file, '-r100');
0063     disp(['File saved       : ' save_file]);
0064     disp(['image file saved : ' save_image_file]);
0065     set(fig, 'Units', oldscreenunits);
0066     
0067     msgbox('File saved.', 'Notice');
0068 end

Generated on Mon 22-May-2023 06:53:56 by m2html © 2005