Hello, How can I use output data from a function as input data to another function?

回答 (1 件)

Geoff Hayes
Geoff Hayes 2017 年 2 月 25 日
salim - presumably your functions are as described at Declare function name, inputs, and outputs and so both have signatures of the form
function [y1,y2,...,yN] = myfun(x1,...,xM)
If your first function returns a matrix, then you can pass that as input parameter into your second function.
Suppose we have a function that generates a transition matrix, F, as
% input parameter t: time in seconds
% output parameter F: transition matrix
function [F] = generateTransitionMatrix(t)
Now suppose we have a second function that calculates the updated state/position given this transition matrix
% input parameter F: transition matrix
% input parameter x: current state vector
% output parameter xp: updated state vector
function [xp] = updateState(F,x)
Our code would then look something like
>> t = 5.0;
>> x = rand(4,1);
>> F = generateTransitionMatrix(t);
>> xp = updateState(F,x);
Our first function returns a matrix that we then use as an input into the second function.

2 件のコメント

salim wadi
salim wadi 2017 年 2 月 25 日
Thanks Dear Geoff Hayes, Actually, I do that first function is * function [wm, AG, WI, HI, hn, IVn, H2OI, AR, rxyOI, AC, ACC, ACF, H2CI, rxyCI] =AESCipher(A, sb_hex, key_hex,IV)* and 2nd function is * function [DCI, H2DI, rxyDI] = AESdecr( sb_hex, Invs_box, IV,wm, AC, ACF, WI, HI)* . So the important matrix is AC, where when execute 2nd function an massage appear (undefined parameter AC).
Geoff Hayes
Geoff Hayes 2017 年 2 月 26 日
salim - are you passing in AC into the second function? How are you calling this second question? Please post the code which shows how you are using both functions.

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeMultidimensional Arrays についてさらに検索

質問済み:

2017 年 2 月 24 日

コメント済み:

2017 年 2 月 26 日

Community Treasure Hunt

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

Start Hunting!

Translated by