How to specify/change function input variable types
12 views (last 30 days)
Show older comments
Hello,
I'd like to add an input, t, to a function, which needs to be type 'double'. Even if I've already defined t as a double, when it gets used as the function input, the function automatically assumes it is type 'char'. My understanding is that the function determines the variable type based on how it is used within the function, and this variable is only used to access a value from an array. The first time it is called, it's something like PV(t,4). Basically I want to run the function several times with different values of t in order to access different parts of an array each time. The function's only other input is a filename.
So, is there another way I can call it that would cause the function to see it as a 'double'? Or, is there a way to change it from 'char' to 'double' within the function? When it sees t as 'char', it is not getting the right value from the array.
Thanks!
0 Comments
Answers (3)
Walter Roberson
on 25 Nov 2011
You almost certainly have a mismatch in the calling sequence between how it is being called and how it expects to be called.
Please carefully compare the call you are making against the "function" declaration for the function. You can put a breakpoint in at the first line of the routine, and if necessary, compare class() of each variable declared in the "function" line against the corresponding variable you pass in, and compare that again to the type your code treats each variable as being.
You indicate that "the function's only other input is a filename", but you show us a call of PV(t,4) and you tell us that t is a double, so your sample code does not show any character being passed in at all.
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!