Hello Guys. I have a question about saving and uploading data with any file name and in any folder. My code is giving me errors and not saving the filename with any name that I want. You can have a look at my edit_callback, upload_callback and pushbutton_callback. Help will be greatly appreciated on how I can fix this.
% --- Executes on button press in pushbutton_Save.
function pushbutton_Save_Callback(hObject, eventdata, handles)% hObject handle to pushbutton_Save (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% get the string data from edit
startingFolder = pwd % Or "pwd" or wherever you want.
defaultFileName = fullfile(startingFolder, '*.mat*');[baseFileName, folder] = uiputfile(defaultFileName, '*.mat*');if baseFileName == 0 % User clicked the Cancel button.
return;endfullFileName = fullfile(folder, baseFileName);fid = fopen(fullFileName, 'wt');if fid ~= -1data = handles.mystructdata;data.Level=handles.Level;save('data')fclose('all')endfunction pushbutton_Upload_Callback(hObject, eventdata, handles)startingFolder = pwddefaultFileName = fullfile(startingFolder, '*.mat');[baseFileName, folder] = uigetfile(defaultFileName, 'Select a mat file');if baseFileName == 0 % User clicked the Cancel button. return;endfullFileName = fullfile(folder, baseFileName)temp = load(fullFileName);data=temp.data;uictagnames = fieldnames(data);for i =1:numel(uictagnames) uicparams = fieldnames(data.(uictagnames{i})); for j = 1:numel(uicparams) evalstr = sprintf('tempval = data.%s.%s',uictagnames{i},uicparams{j}); evalc(evalstr); end endfunction edit_TemperatureValue_Callback(hObject, eventdata, handles)% hObject handle to edit_RotorTemperatureValue (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit_RotorTemperatureValue as text
% str2double(get(hObject,'String')) returns contents of edit_RotorTemperatureValue as a double
if regexp(hObject.String,'^[+-]?[0-9]*(\.(\d)+)?([eE]([+-])?(\d)+)?$|^[0-9]\*10\^[0-9]$')==1else set(hObject,'Enable','inactive') % Edit auf inactive setzen
set(hObject, 'String','Enter a number') uicontrol(hObject) endstr=get(hObject,'String');tagname=get(hObject,'tag');% USE TAGNAME AND VALUE OF THE PROPERTY AS FIELDNAMES FOR THE STRUCTURE
handles.mystructdata.(tagname).string = str;guidata(hObject,handles)
Best Answer