i'm completely new to matlab and this is my first question.
I found a program like this
x = inputdlg('foo');
x = str2num(x{1})
and trying to make some gui from it, put this line to callback function of push button:
x=get(handles.edit1, 'String')
x=str2num(x{1})
and it works, but not after i add this the same thing with different variable
y=get(handles.edit2, 'String')
y=str2num(y{1})
command window said
Cell contents reference from a non-cell array object.
Error in regresilinear>pushbutton1_Callback (line 128)
x=str2num(x{1})
Error in gui_mainfcn (line 96)
feval(varargin{:});
Error in regresilinear (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in
#(hObject,eventdata)regresilinear('pushbutton1_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating uicontrol Callback
I found out that the output from command window is different when it's running and not with the same input.
When it got errors:
x =
0 1 2 3
when not (the first time)
x =
'0 1 2 3'
It doesn't give any error if i delete the str2num line.
I hope somebody can help fix the problem.
Start with a clear workspace and
x=get(handles.edit1, 'String');
x=str2num(x);
or better:
x=str2num(get(handles.edit1, 'String'));
{} are used for accessing the elements of a cell array. You are probably trying to use it on a string and that is why you are getting that error.
Related
I have matrix 3x108 which contains dimension data. I want to find min and max value of my matriks in each row. Here's my code:
P = load('grading/dimension.mat');
min_P = min(P,[],3);
max_P = max(P,[],3);
but it gives me error:
??? Error while evaluating uicontrol Callback
??? Undefined function or method 'min' for input arguments
of type 'struct'.
Error in ==> guikedelaizulfa>identifikasi_Callback at 1427
min_P = min(P,[],3);
Error in ==> gui_mainfcn at 96
feval(varargin{:});
Error in ==> guikedelaizulfa at 42
gui_mainfcn(gui_State, varargin{:});
Error in ==>
#(hObject,eventdata)guikedelaizulfa('identifikasi_Callback',hObject,eventdata,guidata(hObject))
??? Error while evaluating uicontrol Callback
Can you help me? Thanks
Using P=load(...) the function returns a single struct which contains all variables. Assuming you have used the variable name X when saving, you can access the variable using P.X. I recommend to set a breakpoint and take a look at the loaded data using the Variable Explorer or the fieldnames function.
Why do I get the error Cell contents reference from a non-cell array object. Below is my code. Can anybody tell me what is wrong with this code?
%Read data from database.
curs = exec(conn, sprintf(['SELECT description.imageName'...
' , description.brand'...
' , description.price'...
' , description.size'...
' , description.clothingDescription'...
' FROM description WHERE description.imageID ="%s"'],imagename));
curs = fetch(curs);
close(curs);
%Assign data to output variable
results = curs.Data;
disp(results);
set(handles.edit1,'String',results{1});
set(handles.edit2,'String',results{2});
set(handles.edit3,'String',results{3});
set(handles.edit4,'String',results{4});
set(handles.edit5,'String',results{5});
This is the full error message
Cell contents reference from a non-cell array object.
Error in image_desc1>image_desc1_OpeningFcn (line 90)
set(handles.edit1,'String',results{1});
Error in gui_mainfcn (line 220)
feval(gui_State.gui_OpeningFcn, gui_hFigure, [], guidata(gui_hFigure), varargin{:});
Error in image_desc1 (line 42)
gui_mainfcn(gui_State, varargin{:});
This is one of the sample data execute in command window when typing the code in
WHERE description.imageID =1
'High Neck Tee' 'ZALORA' [40] 'S,M,L,XL' 'Blush High Neck by ZALORA'
After typing the whos, it show this sentence in command window
Name Size Bytes Class Attributes
results 1x1 8 double
The error communicates the message clearly as it is. The variable results is not a cell array and you are trying to extract non-existing results{1},...,results{5}. Hence the error.
My code makes a plot and then makes a prompt asking the user if he wants to make another plot with different parameters. The problem is, while questdlg.m is open, the user cannot look at details on the plot.
Here's the code :
while strcmp(Cont,'Yes') == 1
%Some code modifying 'data'
plot(1:X,data);
Cont = questdlg('Would you like to plot another pixel?','','Yes','No','Yes');
close all;
end
I've tried a few things. I tried to create another function called normalquestdlg.m, and I copy pasted the questdlg.m code into it, modifying line 401.
set(QuestFig,'WindowStyle','modal','Visible','on');
to
set(QuestFig,'Visible','on');
I tried different location for the normalquestdlg.m function. Putting it in my default Matlab folder for homemade functions gave me the following error :
Undefined function 'dialogCellstrHelper' for input arguments of type 'char'.
Error in **normalquestdlg** (line 74)
Question = dialogCellstrHelper(Question);
Error in **Plot** (line 40)
Cont = normalquestdlg('Would you like to plot another pixel?','','Yes','No','Yes');
And putting it in the same folder as questdlg.m (C:\Program Files\MATLAB\R2014a\toolbox\matlab\uitools) gave me the following error :
Undefined function 'normalquestdlg' for input arguments of type 'char'.
Error in **Plot** (line 40)
Cont = normalquestdlg('Would you like to plot another pixel?','','Yes','No','Yes');
I even tried to put it as the first path to look for :
p = path
path('C:\Program Files\MATLAB\R2014a\toolbox\matlab\uitools', p)
Cont = normalquestdlg('Would you like to plot another pixel?','','Yes','No','Yes');
path(p)
Needless to say, this didn't change a thing.
Anyone has any tips for me?
No easy solutions were to be found. The easiest thing I could find was to download MFquestdlg.m (http://www.mathworks.com/matlabcentral/fileexchange/31044-specifying-questdlg-position/content/MFquestdlg.m) and modify line 384 of it this way :
set(QuestFig, 'WindowStyle', 'modal', 'Visible', 'on');
to
set(QuestFig, 'Visible', 'on');
since 'normal' is the default WindowStyle.
I prefered to do this than to modify basic Matlab functions. This could be enhanced even more (if someone had the need to do so) by adding an input in the function specifying the WindowStyle (either 'normal', 'modal' or 'docked'), and it would be quite easy, adding too a little fail-proof like line in this style :
if nargin < 8
WinStyle = '%enter default mode'
end
if nargin == 8
if strcmp(WinStyle,'normal') == 1 | strcmp(WinStyle, 'modal') == 1 | strcmp(WinStyle, 'docked') == 1
else
error('MATLAB:questdlg:IncorrectInput', 'The WindowStyle input parameter was incorrectly written')
end
end
My dropdown list contains the ff. strings: Low Pass, High Pass, Band Pass, Stop Band. Whenever I choose the Low Pass, the error below shows. The code below works for the rest.
My goal is to make the edtCutoff2 and txtRange invisible when I choose Low Pass and High Pass but the code below works only for High Pass.
Error:
Error using ==
Matrix dimensions must agree.
Error in untitled>popFreqResp_Callback (line 168)
if ((str == 'Stop Band') | (str == 'Band Pass') == 1)
Error in gui_mainfcn (line 96)
feval(varargin{:});
Error in untitled (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in#(hObject,eventdata)untitled('popFreqResp_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating uicontrol Callback
Code Snippet
function popFreqResp_Callback(hObject, eventdata, handles)
list=get(handles.popFreqResp,'String');
str=list{get(handles.popFreqResp,'Value')};
if ((str == 'Stop Band') | (str == 'Band Pass') == 1)
set(handles.edtCutoff2,'Visible','on');
set(handles.txtRange,'Visible','on');
else
set(handles.edtCutoff2,'Visible','off');
set(handles.txtRange,'Visible','off');
end
You shouldn't compare strings using '==', because it will throw the error you see if the strings are not the same length. Essentially '==' is comparing two matrices of type char - if they don't have the same length, '==' isn't defined. Since 'Low Pass' has a length of 8, and 'Band Pass' has a length of 9, you can't compare them in this manner.
Use strcmp instead. Or strcmpi if you don't care about case.
I've recently been developing a GUI, which worked fine until Matlab crashed while running an unrelated code. A section of my code which allows a user to draw a ROI no longer works and reports an error with my impoly call (worked perfectly before Matlab crashed):
function cb(src,evt)
handles = guidata(src); %# import the data from the object
images=handles.images;
start = handles.view_slice;
last = handles.slices;
imshow(images(:,:,start),[])
h=impoly;
position = getPosition(h);
The error I now get is:
Error using hittest
Invalid object handle
Error in imshared.ipthittest (line 33)
h = hittest(hFigure, currentPoint);
Error in findLowestManagedObject (line 14)
hit_obj =
imshared.ipthittest(hFigure,buttonMotionEvent.currentPoint);
Error in iptPointerManager>createPointerManager/updatePointer
(line 334)
overMe =
findLowestManagedObject(hFigure,mouseMotionEvent);
Error in
iptPointerManager>createPointerManager/enablePointerManager (line
259)
updatePointer(figHandle, evt);
Error in iptPointerManager (line 72)
pointerManager.API.enable();
Error in manageInteractivePlacement (line 76)
iptPointerManager(h_fig,'Enable');
Error in impoly>impolyAPI (line 245)
placement_aborted =
manageInteractivePlacement(h_axes,h_group,#placePolygon,#buttonUpPlacement);
Error in impoly (line 97)
[h_group,draw_api] = impolyAPI(varargin{:});
Error in volume_scan>cb (line 288)
h=impoly;
Error while evaluating uitoggletool OnCallback
Apart from this not working, there is other weirdness including text stuck in a table on GUIDE (which I cannot remove) and a checkbox text which keeps defaulting to the 3rd option
Anybody got any ideas? Is there a crash file somewhere that needs to be reset/removed? I'm using 2012b.
Thanks, Jim