jball
jball

Reputation: 3

When calling a function in matlab, how can I output the result to a matrix in the original file?

Basically I would like to call a function that I have written, and because of the amount of results, I would like the function to output its solution into a matrix that gets passed to the program that called it.

Upvotes: 0

Views: 1918

Answers (2)

Laurie
Laurie

Reputation: 1

The confusing part (to me) was that you need to put the output variables in both your main program and your function definition. So in your main program you have:

[out1,out2,out3] = function_name(in1,in2);

and in your function definition, you have:

function [out1,out2,out3] = function_name(in1,in2).

The variables don't have to have the same name, but they need to be oriented similarly, so that you can then pass the outputs back to the main program.

Upvotes: 0

eykanal
eykanal

Reputation: 27047

You define the output of a function in the function declaration at the top of your script:

function [output] = myFunction(input)

All you need to do is define the output variable somewhere in your script.

Upvotes: 1

Related Questions