| New Reply |
Calling function with no input argument |
Share Thread |
| Feb10-12, 09:54 AM | #1 |
|
|
Calling function with no input argument
Hi guys,
I am going to ask another very stupid question. But surprisingly, I could not find any help on it on internet. My question is: I have defined a function which doesn't take any any input and one output. When I called it, the program halts. I have checked the function and it is working fine seperately. My be i am making mistake in calling it. Her is how I defined it: function [sumout] = sortabc() .... end Here is how I am calling it: sumout = sortabc(); Can anybody kindly tell me if I am making any mistake in calling ir defining the function sortabc. Regards. |
| Feb11-12, 07:33 AM | #2 |
|
|
I guess you are talking Matlab, right?
I don't use matlab, but I would like to think that I am a good detective since I do fine in my programming and debugging. So, here are some stupid suggestions, not knowing matlab and simply having done a google on function definitions in matlab: do you have a file named sortabc.m ? is matlab case sensitive? what does the file name look like from the file system? are you working on Windows or Linux? do you need to enclose the output argument in square brackets? like [sumout] = sortabc() or is that only needed when you have more than one argument? Otherwise, do what I refer to "baby steps" ...go back and define a trivial function that should work, like one that does nothing important but returns, say 9... and go from there...if that does not work, maybe something along what I asked above is happening? |
| Feb13-12, 02:10 AM | #3 |
|
Recognitions:
|
You don't say what you are coding in. But based on my extensive coding experience ![]() I can say what you wrote looks wrong or at least weird. (Though that's not to say it's not right.) Code:
Here is how I am calling it: sumout = sortabc(); Code:
function [sumout] = sortabc() .... end Code:
fuction sortabc() ... sortabc='thesortedstring' end |
| Feb21-12, 04:03 PM | #4 |
|
|
Calling function with no input argument
I had the same problem, and similarly could not find an answer online. But here it is:
Assuming you are using Matlab, you do not need the parentheses when you call the function. You defined it correctly (although you shouldn't need brackets): function sumout = sortabc(); When you call a function with no inputs, do not use parentheses: sumout = sortabc; Using the same variable names shouldn't be a problem. Their domains don't overlap. |
| New Reply |
Similar discussions for: Calling function with no input argument
|
||||
| Thread | Forum | Replies | ||
| Fortran Routine calling a Python Function | Programming & Comp Sci | 2 | ||
| Beginner Function Calling Question | Programming & Comp Sci | 2 | ||
| C++ Function Calling | Programming & Comp Sci | 7 | ||
| Fortran; Calling an executable that in turn runs an input file | Programming & Comp Sci | 1 | ||
| Problems With Calling A Function | Engineering, Comp Sci, & Technology Homework | 2 | ||