Can't enter inputs unless using workspace values
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
dpb
am 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.
Antworten (1)
Walter Roberson
am 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.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!