Accessing data variables from another function
18 views (last 30 days)
Show older comments
Billy Worley
on 17 Nov 2019
Commented: Billy Worley
on 17 Nov 2019
I have a function, F1, that will perform a certain amount of calculations, with the results as variables Q and R. The input for F1 is A, an n x n matrix. I need to write another function, F2, that calls F1 and uses Q and R to calculate a new output, A2. This A2 needs to be run back through F1 to calculate a new Q and R, which will then be run through F2 again, to calculate A3, and so on.
My logic behind this is that I can create a for-loop that tags into F1 each iteration, and updates A2 to be A each time. I'm thinking this is possible, but not sure if it is.
Anyhow, the problem I am having is acessing those variables from F1. For example (using a toned down version, I have many more variables in mine):
1st function:
function [Q,R] = F1(A)
Q = 2*A
R = 3*A
end
-------------------------------------------------
2nd function:
function d = F2(A)
fun = @F1
--------------------------------------------
command window input:
F2([1,1,1 ; 2 2 2 ; 3 3 3]
In order for my process to work, my F2 needs to make calculations based on the variables from F1. How can I access those variables, or have those variables input into my workspace, before the function ends? It has to be in this format, a function F1 and function F2.
0 Comments
Accepted Answer
Erivelton Gualter
on 17 Nov 2019
I did not get the final goal, but I fixed your code.
F2([1,1,1 ; 2 2 2 ; 3 3 3])
function [Q,R] = F1(A)
Q = 2*A
R = 3*A
end
function d = F2(A)
[Q,R] = F1(A);
d = [];
end
More Answers (0)
See Also
Categories
Find more on Whos in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!