Can't enter inputs unless using workspace values
조회 수: 1 (최근 30일)
이전 댓글 표시
I am a new Matlab user, and I am slowly learning how to use the program. However, I keep running into an issue, and I am going to explain it to the best of my ability. Sometimes, when I enter values for my inputs, an error message pops up, dispite the code being fine. For example, one of my programs was finding pythagorean triples, and when it asks for side lengths a, b, and c, I will enter 3, 4, and 5, and it should display the message that "This is a pythagorean triple". Instead, however, it displays an error message. However, if I go into the command window, type a=3, b=4, and c=5, then run the code, and side lengths a,b,c as a,b,c, it will display it for me. Now, I am pretty sure that the code is right, I just don't know how to change it from displaying that error message, because I need to be able to enter values in for the inputs. Does anyone know the solution to that? Thank you
댓글 수: 3
dpb
2022년 9월 3일
We've got to see all the code -- how you wrote it to return the variables is key point here and we can't see your terminal from here to know what you did, precisely. Verbal descriptions of what you think you did aren't good enough; computers are very unforgiving things and the minute details are critical.
답변 (1개)
Walter Roberson
2022년 9월 3일
You are using input() but the code is not assigning the values to the variables.
If you input() and expect the user to enter 3 values, then you should be testing that the response isnumeric() and numel() is 3 and the entries are positive integers. Then you should use indexing to assign to the individual variables.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!