Uploading a value with a Matrix into MATLAB GUI
Mostrar comentarios más antiguos
Hello Guys. I hope you are doing well. I have a question related to the uploading the value with a matrix. My code for the upload_ callback is working for all values except for the edit text box with a matrix and a value. How can I change the code below so that I can upload the value with the matrix as well? Any help will be greatly appreciated. I get the following errors when I use the pushbutton upload code shown below. These errors only come when I try to upload the value with the matrix edit box and not for the other edit text boxes.
Error using sprintf
Function is not defined for 'cell' inputs.
Error in GUI_ParametersFinal>pushbutton_Upload_Callback (line 149)
evalstr = sprintf('set(handles.%s,''%s'',''%s'')',uictagnames{i}, uicparams{j},tempval);
Error in gui_mainfcn (line 95)
feval(varargin{:});
Error in GUI_ParametersFinal (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in @(hObject,eventdata)GUI_ParametersFinal('pushbutton_Upload_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating UIControl Callback
The code is:
function pushbutton_Upload_Callback(hObject, eventdata, handles)
startingFolder = pwd
defaultFileName = fullfile(startingFolder, '*.mat');
[baseFileName, folder] = uigetfile(defaultFileName, 'Select a mat file');
if baseFileName == 0
return;
end
fullFileName = 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)
tempval = data.(uictagnames{i}).(uicparams{j});
if ~isnumeric(tempval)
evalstr = sprintf('set(handles.%s,''%s'',''%s'')',uictagnames{i}, uicparams{j},tempval);
else
evalstr = sprintf('set(handles.%s,''%s'',%d)',uictagnames{i}, uicparams{j}, tempval);
end
evalc(evalstr);
end
end
For edit callbacks, I am using this code:
str=get(hObject,'String');
tagname=get(hObject,'tag');
handles.mystructdata.(tagname).string = str;
guidata(hObject,handles)
The value in the edit text box is being generated from another GUI in the button down function. The value is getting saved, but once I click on the upload button, all the values get uploaded except for the value shown below because it is a value with matrix.
For all other structs, I have 1 fields. Only for this struct, I have 2 fields. Any help will be greatly admired as I am working on a big project. I had taken the help for uploading the values of the edit text boxes from this link. Therefore, you can see the link as well. I just need to upload the value with the matrix as shown above. Everthing else is done.
1 comentario
The link you gave uses really very badly writen code: in general, I would not recommend copying code from people asking questions: the reason they are asking questions is because they don't know what they are doing. And anyone using evalc to set the field of a handles structure really doesn't know what they are doing.
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Common Operations en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

