Variable number of output arguments in a function
显示 更早的评论
Hi guys. I'm sorry if this is a basic question but I'm stuck. I have a function that I need to keep very general, since it's attached to a switch menu where I test three different structural elements from three differents POV (frontal, crest, back) using another switch menu. The problem is that I need to detect colors, but colors change in type AND also in quantity. Being the max number 3, I have a problem in the crest where I just have one color. The best way would be to 'mute' the variables of the other 2 colors but how do I do it? If I put [] the program crashes. Basically sometimes I don't need to use all the variables and I need them not to interfer with the rest of the code.
回答(1 个)
10 个评论
giacomo
2017-9-28
it doesn't work
Your question and the details you've given are far too generic for us to know why it doesn't work, whatever it is
The problem is that the program still looks for...
The program does exactly what you wrote it to do, nothing less, nothing more. If it doesn't do what you want, then change it to do what you want. Unfortunately, as you've given so little details how anything is implemented, I don't see how we can give you more advice.
giacomo
2017-9-28
Adam
2017-9-28
Your question is about a variable number of input arguments, but your function has no input arguments at all.
giacomo
2017-9-28
Jan
2017-9-28
"A function like ..." is not useful. Obviously the details matter and your rough pseudo-code does not contain the details. This is completely unclear:
case 2 -> I set and use only 3 variables -> crashes
case 3 -> see case2 -> crashes
Please post the real code.
giacomo
2017-9-28
Jan
2017-9-28
I'm astonished. What are "those" variables? You "tried to comment the ones I didn't need"? Where? I do not see commented variables. Therefore I still cannot guess, what the problem is.
Come on, giacomo, we want to help you. Really. So post the failing code and explain exactly, what is failing: show us the complete copy of the error message or explain the difference between your expectations and the result. Which code causes which problem? As long as you keep this information as a secret, we cannot help you to solve the problem.
giacomo
2017-9-28
giacomo
2017-10-4
类别
在 帮助中心 和 File Exchange 中查找有关 Model Compatibility 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!