Is there a way to change the value of a variable within a function?

2 views (last 30 days)
Hi everyone,
I was wondering for a function with 4 arguments within it, can I change the value of 2 arguments multiple times and keep two arguments constant, and get an output for the function each time under the same set of data for output?
eg
function v=fctionname (a1,a2,a3,a4)
a1 = 2
a2 = 4
a3 = variable value (changed say 7 times)
a4 variable value (changed say 7 times)
producing
v = 7 different values
Many thanks!

Accepted Answer

dpb
dpb on 8 Nov 2020
You can do anything you want inside the function as long as you can write a definition of what it is that is to happen.
You could pas the a3, a4 variables as arrays and use them as most transparent way but most required of user. If the initial value of a3, a4 are needed and modified, then that's easy enough, too. Or, if they are totally defined by the function, they wouldn't even need to be arguments.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!