After convert gui to exe, creat a new file in a certain path does not work in other computers with exe installed, but locally works. Is the problem because of 'fopen' part ?
1 view (last 30 days)
Show older comments
if true
function save_button_Callback(hObject, eventdata, handles)
% hObject handle to save_button (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
handles = guidata(handles.output);
name = handles.dataname;
%parameters = [''Date: ''; 'Exposure Time: '; 'Voltage: '; 'Correction Method: '; 'Window Size: '; 'Step Size: '];
data = num2cell([handles.RS handles.BC]);
items = cellstr(char('Date: ', 'Exposure Time: ', 'Voltage: ', 'xmin: ', 'xmax: ', 'Method: ', 'Window Size: ', 'Step Size: '));
parameters = cellstr(char(handles.date, handles.exposure, handles.voltage, num2str(handles.xminDef), num2str(handles.xmaxDef), ...
handles.correct_method, num2str(handles.winsize), num2str(handles.stepsize)));
save_data = cell(size(data,1), 4);
save_data(:, 1:2) = data;
save_data(1:length(items), 3) = items;
save_data(1:length(parameters), 4) = parameters;
save_path = get(handles.edit11, 'String');
if(isempty(save_path) == 1)
str = get(handles.edit1, 'String');
mkdir(str, 'BaselineCorrected');
save_path = strcat(str, '/BaselineCorrected');
set(handles.edit11, 'String', save_path);
end
handles.savepath = get(handles.edit11, 'String');
file = fopen(fullfile(handles.savepath, [name(1:end-4), '_BaselineCorrected.dat']), 'wt+');
formatSpec = '%15.2f %15.4f %15s %15s\r\n';
[nrows,ncols] = size(save_data);
for i = 1:nrows
fprintf(file, formatSpec, save_data{i,:});
end
fclose(file);
guidata(hObject,handles);
end
Answers (1)
Walter Roberson
on 11 Feb 2016
handles.edit11 might be non-empty but with the information given we do not know that it is valid. If it is empty then handles.edit1 will be used to create a directory and path, but we do not know that handles.edit1 is valid.
Your mkdir() should have a try/catch around it in case creating the directory fails.
Your fopen() should have two outputs and you should be checking if the first output is negative and displaying the second output (error message) if so.
2 Comments
See Also
Categories
Find more on Introduction to Installation and Licensing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!