cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Visit the PTCooler (the community lounge) to get to know your fellow community members and check out some of Dale's Friday Humor posts! X

Returning Multiple Values from a Function

OscarJ.
1-Newbie

Returning Multiple Values from a Function

Good morning,

I have been working in a problem that requires several steps in one function. Is like creating several tables and each one with specific information. At the end, my interest is the final value of one of those "tables", but it would be nice if I can show the result of the others tables (the entire table). Please see attached example, to understand a little bit more my issue: There are two functions ("Func" and "Func2" they are the same but they have a different return) with a loop. In each iteration I am creating a new row of each "table", and using that information I estimate the next. The tables should handle units, so that's why I use arbitrary units in this example.

My question is: as you can appreciate I use two functions to get the required value and the "other tables", but they are actually the same. do you know if there is any way I can get all (value and "tables") from the first function? something like multiple return?

Thanks a lot,

OJ.

1 ACCEPTED SOLUTION

Accepted Solutions

something like multiple return?

No, just one return value allowed, but you can put all you want to return in a vector or matrix. But as you probably know you would have to take care that all matrix elements must have the same unit (or none).

Maybe something like the attached would help?

EDIT: Added a third method at the end

View solution in original post

3 REPLIES 3

something like multiple return?

No, just one return value allowed, but you can put all you want to return in a vector or matrix. But as you probably know you would have to take care that all matrix elements must have the same unit (or none).

Maybe something like the attached would help?

EDIT: Added a third method at the end

Hello Werner,

Thanks for your reply. It was really helpfull.

I was thinking of adding a second parameter to my function, so I can decide what to return based on that. Please see document attached.

Best,

OJ

I was thinking of adding a second parameter to my function, so I can decide what to return based on that.

Nice touch!

Top Tags