Counting how many times an option is selected inside a loop

조회 수: 7 (최근 30일)
Cathan Ivory
Cathan Ivory 2021년 5월 12일
답변: gotjen 2021년 5월 12일
I am trying to create a piece of code that will display how many times an option from the list has been selected. I have a loop that will keep occuring until the user has finished inputting the data. Here is a section of that code.
for k = 1:1:A(w,2)
normal=normal+1;
list = {'Resident','Education','Office','Toilet','Storage'};
[indx,tf] = listdlg('PromptString',sprintf('On Floor %d what spaces are used ',w)...
,'SelectionMode','single','ListString',list);
typeofspace = list{indx};
Thanks
  댓글 수: 1
gotjen
gotjen 2021년 5월 12일
Please use code formating on your code. Highlight the code and press alt+enter

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

답변 (1개)

gotjen
gotjen 2021년 5월 12일
You could track the selections with an array like
list = {'Resident','Education','Office','Toilet','Storage'};
count = zeros(size(list))
for kk = ...
[indx,tf] = listdlg(...)
count(indx) = count(index)+1;
end

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by