Troubleshooting Multiple Inputs in Matlab Functions: Common Errors and Solutions

  • Context: MATLAB 
  • Thread starter Thread starter PieceORock
  • Start date Start date
  • Tags Tags
    Matlab
Click For Summary

Discussion Overview

The discussion revolves around troubleshooting issues related to passing multiple inputs into a MATLAB function. Participants explore the nature of the error encountered when calling the function and examine how inputs are being handled in the context of another function.

Discussion Character

  • Technical explanation
  • Debate/contested

Main Points Raised

  • One participant describes an issue with a MATLAB function that throws an error regarding an undefined input argument when attempting to use multiple inputs.
  • Another participant asserts that there is no problem with the function definition itself and questions whether the function is being called correctly.
  • A third participant confirms that the function works when called with two arguments, suggesting that the error may arise from calling the function with insufficient arguments.
  • A participant explains their method of defining arrays for inputs and indicates they are using another function, Trap, to call my_func1, which may not be passing the inputs correctly.
  • One participant points out that the way the function Trap is called does not directly invoke my_func1, implying that the error may stem from how inputs are being managed within Trap.

Areas of Agreement / Disagreement

Participants generally agree that the function definition is correct, but there is disagreement regarding how the function is being called and whether the inputs are being passed properly. The discussion remains unresolved as to the specific cause of the error.

Contextual Notes

There are limitations in understanding how the function Trap is implemented, particularly regarding how it handles the input string and the number of arguments passed to my_func1. The exact nature of the error within Trap is not fully explored.

PieceORock
Messages
2
Reaction score
0
I am having problems putting multiple inputs into a function file. This is what I have.

function y = my_func1(r ,V)
y=6.28.*r.*V;

When I try to use this function, it says:

? Input argument "V" is undefined.

Switching r and V gives the same error, but it is always the second variable that throws the error. If anybody knows if I am putting this in wrong, please let me know
 
Physics news on Phys.org
I don't see any problem with that function. Are you sure your calling the function properly?
 
There's nothing wrong with that function. (I assume you're saving it as my_func1.m).

It works fine for me as long as I call it with 2 arguments, i.e
> my_func1(2,3)

I can reproduce your error message exactly if I call it with only 1 argument. You wouldn't be doing that by any chance, would you?
 
I don't know if I'm calling it incorrectly. I made two arrays, one for r and one for V like this r=[1 2 3] and V=[1 2 3] in the command window. Then I am called another function with the line I = Trap('my_func1', 0, 1, 1)
where the numbers are just inputs to another function.
 
By writing the line

I=Trap('my_func1', 0, 1, 1)

You are not calling the function my_func1.

You are calling the function Trap with the inputs being the string (not the function) 'my_func1' and then three input variables.

Inside the function Trap, you will probably find a line which calls whatever the input string is. That function call most likely only has one input variable which is why you are getting undefined input variables.
 

Similar threads

  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 4 ·
Replies
4
Views
4K
  • · Replies 6 ·
Replies
6
Views
4K
  • · Replies 9 ·
Replies
9
Views
3K
  • · Replies 6 ·
Replies
6
Views
2K
  • · Replies 4 ·
Replies
4
Views
10K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 5 ·
Replies
5
Views
9K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 14 ·
Replies
14
Views
4K