Accessing data variables from another function
조회 수: 16 (최근 30일)
이전 댓글 표시
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
채택된 답변
Erivelton Gualter
2019년 11월 17일
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
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Whos에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!