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!