Can I save my outputs in a way to use them as my inputs for the next run?

15 vues (au cours des 30 derniers jours)
Hi suppose I have:
[D C] = function(A,B)
C = A*B;
D = A+B;
end
A and B are my inputs,so after I run the function I can calculate C and D. the second time I am running the function, I want to have my input as this way: A = C and B = D. but I don’t want to change the inputs manually every time. In other words every time I run the function, I want to have A and B replaced by C and D and then running the function without any needs to change my inputs manually every time. Is there anyway I can do this in Matlab? Thanks,

Réponse acceptée

Jos (10584)
Jos (10584) le 21 Fév 2018
Assuming the function above in a m-file, called MyFunction.m
function [C,D] = MyFunction (A,B)
C = A*B ;
D = A+B ;
you can call this function in another script/function like this
A = 1 ;
B = 2 ;
disp([0 A B]) ;
for k = 1:5,
[A,B] = MyFunction(A,B) ;]
disp([k A B]) ;
end

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by