No result being displayed in Edit box
1 次查看(过去 30 天)
显示 更早的评论
Using some value in listbox1 i am calculating value d which is being entered into edit9. The value in edit9 and some other value in edit10 (calculated in same way as edit9) , needs to be added and fed to edit21. But i am getting no value in edit21. Please guide
function listbox1_Callback(hObject, eventdata, handles)
% hObject handle to listbox1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = cellstr(get(hObject,'String')) returns listbox1 contents as cell array
% contents{get(hObject,'Value')} returns selected item from listbox1
b = str2double(handles.edit1.String);
% Get list of everything in the listbox.
listboxItems = handles.listbox1.String;
% Get the index of the item they selected.
selectedItem = handles.listbox1.Value;
% Turn that selection into a double number.
listboxNumber = str2double(listboxItems{selectedItem});
listboxString = listboxItems{selectedItem};
c = -inf;
if strcmpi (listboxString,'None')
handles.listbox2.Enable ='Off';
handles.listbox3.Enable ='Off';
handles.listbox4.Enable ='Off';
handles.listbox5.Enable ='Off';
handles.listbox6.Enable ='Off';
warningMessage = sprintf('No Rod has been Selected');
uiwait(errordlg(warningMessage));
handles.edit9.String = 'No Rod has been Selected';
set(handles.edit1,'String','');
set(handles.edit9,'String','');
handles.edit1.Enable ='Off';
handles.edit9.Enable = 'Off';
elseif listboxNumber == 1.25
handles.listbox2.Enable ='On';
handles.edit1.Enable = 'On';
handles.edit9.Enable = 'On';
c = 4.538;
if isnan(b)
warningMessage = sprintf('Length of Rod Taper is empty');
uiwait(errordlg(warningMessage));
handles.edit9.String = 'Length of Rod Taper is empty'
return;
end
elseif listboxNumber == 1.125
handles.listbox2.Enable ='On';
handles.edit1.Enable = 'On';
handles.edit9.Enable = 'On';
c = 3.676;
if isnan(b)
warningMessage = sprintf('Length of Rod Taper is empty');
uiwait(errordlg(warningMessage));
handles.edit2.String = 'Length of Rod Taper is empty'
return;
end
elseif listboxNumber == 1
handles.listbox2.Enable ='On';
handles.edit1.Enable = 'On';
handles.edit9.Enable = 'On';
c = 2.904;
if isnan(b)
warningMessage = sprintf('Length of Rod Taper is empty');
uiwait(errordlg(warningMessage));
handles.edit9.String = 'Length of Rod Taper is empty'
return;
end
elseif listboxNumber == 0.875
handles.listbox2.Enable ='On';
handles.edit1.Enable = 'On';
handles.edit9.Enable = 'On';
c = 2.224;
if isnan(b)
warningMessage = sprintf('Length of Rod Taper is empty');
uiwait(errordlg(warningMessage));
handles.edit9.String = 'Length of Rod Taper is empty'
return;
end
elseif listboxNumber == 0.75
handles.listbox2.Enable ='On';
handles.edit1.Enable = 'On';
handles.edit9.Enable = 'On';
c = 1.634;
if isnan(b)
warningMessage = sprintf('Length of Rod Taper is empty');
uiwait(errordlg(warningMessage));
handles.edit9.String = 'Length of Rod Taper is empty'
return;
end
elseif listboxNumber == 0.625
handles.listbox2.Enable ='On';
handles.edit1.Enable = 'On';
handles.edit9.Enable = 'On';
c = 1.135;
if isnan(b)
warningMessage = sprintf('Length of Rod Taper is empty');
uiwait(errordlg(warningMessage));
handles.edit9.String = 'Length of Rod Taper is empty'
return;
end
end
%c = str2double(c);
% Do the multiplication.
d = b * c;
% Send the result into edit field 3.
%handles.edit9.String = sprintf('%.f', d);
handles.edit9.String = num2str(d);
function edit9_Callback(hObject, eventdata, handles)
% hObject handle to edit9 (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 edit9 as text
% str2double(get(hObject,'String')) returns contents of edit9 as a double
t = str2double(handles.edit9.String);
if isnan(t)
tt =0;
else
tt =t;
end
%z = tt ;
handles.edit21.String = num2str(tt);
采纳的回答
Aghamarsh Varanasi
2021-3-18
Hi,
Try using the 'set' function to assign values in guide.
set(handles.edit21, 'String', num2str(tt));
Hope this helps
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Migrate GUIDE Apps 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!