Necro1992
Necro1992

Reputation: 139

Matlab GUI Error Value

I have a MATLAB program that I am doing a GUI for. It has several inputs and outputs and all are working fine except for one and I have no idea why.

The input is Area_Cov, this input is not changed in the code, it is just used.

In the GUI, I used an edit box for it, named its tag "Area_Cov" This is the edit box call back function, and i've used the same code for many other boxes, which are working fine.

function Area_Cov_Callback(hObject, eventdata, handles)
% hObject    handle to Area_Cov (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 Area_Cov as text
%        str2double(get(hObject,'String')) returns contents of Area_Cov as a double

v = (get(hObject,'String')); %get recently entered string

if (str2num(v) <= 0)
  waitfor(warndlg('Area value has to be real','!! Warning !!'))
         (warndlg('The value will be set to 10452','!! Warning !!'))
         set(hObject,'String',10452);
else
  Area_Cov = handles.Area_Cov; %update saved value
end

 x = get(handles.Area_Cov,'String'); 
 if isempty(x)
   waitfor(warndlg('Must specify Area Covered','!! Warning !!'))
         (warndlg('Value set to 10452','!! Warning !!'))
          set(hObject,'String',10452);
end


guidata(hObject,handles)

When i push the button calculate, I have the following concerning Area_Cov

Area_Cov=handles.Area_Cov;
assignin('base', 'Area_Cov', Area_Cov);

When i run the code, and press the push button, everything seems to be working fine. But when i try to check the value of Area_Cov in matlab, i always get the value 259.0017

I deleted the box, wrote it again, changed Area_Cov to Area_Covered, check the matlab code, and there isn't anywhere in the code, or the GUI code, where Area_Cov has an input other than the edit box, and nowhere were this value is equal to 259.0017. Furthermore, if i don't change the value in the box, which is 10452 at first, the value will stay the same, otherwise it will change to 259.0017 only.

The code is working fine for many other boxes, so I don't think it is the issue.

Anyone had this problem before ? HELP

Upvotes: 0

Views: 94

Answers (1)

nkjt
nkjt

Reputation: 7817

Area_Cov = handles.Area_Cov; just sets Area_Cov to the handle, not the contents of the handle. (259.0017 is a likely numerical representation of this). What you presumably want to set it to is the numerical value represented by str2num(v), which you use to check validity of the input and then never use again.

It's also not clear to me why you're calling get twice and what the difference between x and v might be.

Upvotes: 1

Related Questions