Can't enter inputs unless using workspace values

조회 수: 2 (최근 30일)
Jason
Jason 2022년 9월 3일
답변: Walter Roberson 2022년 9월 3일
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
Jason
Jason 2022년 9월 3일
So at first, to see if the code works and is accurate, I entered 3, 4, and 5 because it is a simple pythagorean triple and it should display as "This is a pythagorean triple", and when I ran it, the error messgae popped up saying "Unrecognized function or variable 'a'." and "error in line 6". My equation is 0 == a^2+b^2-c^2. I have tried the normal a^2+b^2==c^2, and c==sqrt(a^2+b^2), and tried with only one equal sign as well.
dpb
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
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.

카테고리

Help CenterFile Exchange에서 Numerical Integration and Differential Equations에 대해 자세히 알아보기

태그

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by