필터 지우기
필터 지우기

I don't get the answer that i want?

조회 수: 4 (최근 30일)
Ahmed Alshehhi
Ahmed Alshehhi 2018년 4월 24일
댓글: Ahmed Alshehhi 2018년 4월 24일
went I select number from between 1 to 10 I should get the result = normal and Acc =100 but wwhen I run it I get result = normal and Acc=0. so can anyone help my finding the error?
prompt = 'Select the number: ';
iii= input(prompt);
for iiii=1:10
if z(iii)==0
result= 'normal';
Acc='100%';
else
result ='patient';
Acc='0%';
end
end
for iiii=11:30
if z(iii)==0
result= 'patient';
Acc='100%';
else
result ='normal';
Acc='0%';
end
end
  댓글 수: 3
James Tursa
James Tursa 2018년 4월 24일
It is not really clear what you are trying to do. Can you give some short examples of inputs and desired outputs? Also, picking iii and iiii as variable names is a really good way to confuse the reader. Pick better names.
Ahmed Alshehhi
Ahmed Alshehhi 2018년 4월 24일
The function z is giving the output of 30 data which is should be equal to 0 and i have divide it into two set from 1:10 and 11:30 base in my fuction z every set have different meaning so i used the above loop

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

채택된 답변

Steven Lord
Steven Lord 2018년 4월 24일
There are several areas for improvement or issues that you should correct in your code.
  1. Your for loop variable name contains 4 lower-case I characters and that variable is never used inside the loop, so the loops are completely unnecessary.
  2. Related to the first item, you should use descriptive (and easily distinguishable) names for your variables. The names iii and iiii are not descriptive and it would be easy, after working on this code for a while, to forget what each one represents and accidentally use iiii instead of iii. Don't be like this guy.
  3. If you want to check if the number is one of a specific set of numbers (like 1, 2, or 3) you can use the ismember function or the switch and case keywords.
  4. If you want to check if the number is between certain bounds (like determining if x is between 1 and 3 inclusive) use the relational operators like (1 <= x) & (x <= 3).

추가 답변 (1개)

Benjamin Großmann
Benjamin Großmann 2018년 4월 24일
편집: Benjamin Großmann 2018년 4월 24일
What is the purpose of your code? You prompt for iii (3xi) and loop through iiii (4xi); Within the loops nothing changes, right?
The last else statement is (somehow) fullfilled and the variables are then result ='normal'; Acc='0%'; I can not see some problem here as long as you do not provide z and a proper input for iii which can reproduce some kind of error.
  댓글 수: 1
Ahmed Alshehhi
Ahmed Alshehhi 2018년 4월 24일
the function z is output equal to 0 or 1 for 30 data so, i divide it into two set from 1:10 and 11:30 and i ask the user to select number between 1:30 to check in which result he get , but when i run and for example when i entering the value 1 for iii I get result = normal and Acc =0 which should be 100

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

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by