No result being displayed in Edit box

조회 수: 1 (최근 30일)
Avinav Kumar
Avinav Kumar 2021년 3월 16일
답변: Aghamarsh Varanasi 2021년 3월 18일
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);
  댓글 수: 2
Avinav Kumar
Avinav Kumar 2021년 3월 16일
sum of value of edit 9 and edit10 needs to be displayed in edit 21
Avinav Kumar
Avinav Kumar 2021년 3월 16일
even if we try to print edit9 value in edit21, its not hapenning.

댓글을 달려면 로그인하십시오.

채택된 답변

Aghamarsh Varanasi
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개)

카테고리

Help CenterFile Exchange에서 Whos에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by