How to assign different value to selection in listbox.

1 回表示 (過去 30 日間)
Avinav Kumar
Avinav Kumar 2021 年 3 月 14 日
回答済み: R 2024 年 5 月 8 日
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
str1 = cellstr(get(handles.listbox1, 'string'));
val1 = get(handles.listbox1, 'value');
if isempty(val1)
selection1 = '';
else
selection1 = str1{val1};
end
a = selection1;
b = str2double(handles.edit1.String);
c = a + b;
handles.edit2.String = num2str(c);
b = str2double(handles.edit1.String);
if isnan(b)
warningMessage = sprintf('b is empty.\nPlease put something in the edit field for b.');
uiwait(errordlg(warningMessage));
handles.edit2.String = 'Please enter b';
return;
end
i want to assign some other values to val1 using if else ...how can it bo done

回答 (1 件)

R
R 2024 年 5 月 8 日
Based on your description, I understand you want to understand about if, elseif and else functions in MATLAB. Consider leveraging this documentation:
If you have any alternate or additional queries regarding this, let me know!

カテゴリ

Help Center および File ExchangeMigrate GUIDE Apps についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by