Can't enter inputs unless using workspace values

1 view (last 30 days)
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 Comments
Jason
Jason on 3 Sep 2022
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 on 3 Sep 2022
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.

Sign in to comment.

Answers (1)

Walter Roberson
Walter Roberson on 3 Sep 2022
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.

Categories

Find more on Numerical Integration and Differential Equations in Help Center and File Exchange

Tags

Products


Release

R2022a

Community Treasure Hunt

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

Start Hunting!