getting the error matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)sam('pushbutton1_Callback',hObject,eventdata,guidata(hObject)) Error while evaluating UIControl Callback.
Afficher commentaires plus anciens
I am just experimenting with GUIDE as I am new to it. I am trying to read the text from an edit box and open the image with the name that I read from the edit box.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
y=get(handles.edit2,'String');
number=imread(y);
imshow(number);
This is giving an error. However if I make this change :
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
x='7.jpg'
number=imread(x);
imshow(number);
The code works fine. This isn't making much sense to me. All I'm doing is extracting the string from the editbox and calling the function imread using that string. The code works if I intitialize my own string, but not when I extract one from the edit box
Réponses (1)
Walter Roberson
le 15 Mar 2018
Modifié(e) : Walter Roberson
le 15 Mar 2018
0 votes
get(handles.edit2,'String') is not certain to return a character vector:
- if you initialized it with a cell array of character vector then the String property will return a cell array of character vector, even if the user edited the string
- if you initialized it with character vector then the String property will return a character vector or character array (if the Max property is greater than 1) even if the user edited the string. Special case: if you initialized it with a character vector that includes newline characters and Max > 1 then the character vector will be split into rows at each newline, giving you a char array.
- if you initialized it with a string() scalar then the String property will return a character vector
- if you initialized it with a string() array then the String property will return a cell array of character vectors, the result of cellstr() applied to the string() array
- some of the fine details depend on whether Max > 1 or not. Historically I have seen an edit control switch between a character vector and a cell array of string depending on exactly how the user edited.
Typically when you are working with an edit box, the safest thing to do is to cellstr() and then to check whether the cell is a scalar and then deference the cell if it is.
1 commentaire
Praveer Jain
le 13 Jan 2021
Hello Walter
I am also having similar issue. How do I use cellstr() function? Do I directly mention the variable name in the function?
In my case,
LIG=str2double(get(handles.edit1,'string'));
Matlab is not taking the above value. It is showing the error 'Struct contents reference from a non-struct array object.'
If I feed the data manually, then code is running fine.
Catégories
En savoir plus sur Characters and Strings dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!