How to set the value of a variable in one function from another?

30 ビュー (過去 30 日間)
Ryan O Malley
Ryan O Malley 2022 年 4 月 8 日
コメント済み: Ryan O Malley 2022 年 4 月 8 日
I have a function in its own file that has the variable n. I want to run the function in a loop incrementing the value for n each time in another function file. I am able to access the value of n if its set prior but I dont know how to change it from my second function.
Any help would be greatly appreciated.
Its something like this.
function[n,x,y] = f1
n;
//code that does stuff with n
end
Then in my second function I have the following loop where I call f1 and want to change the value of n each time/
function f2
for k=1:5
n=k
[n,x,y] = f1
end
end
  1 件のコメント
KSSV
KSSV 2022 年 4 月 8 日
n is the out put from f1 obtained after some calculation. Why and how you want to change it?

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

採用された回答

per isakson
per isakson 2022 年 4 月 8 日
Modify the function so that f1 takes n as an input argument
function [n,x,y] = f1( n )
n;
//code that does stuff with n
end
function f2
for k=1:5
n=k
[n,x,y] = f1( n );
end
end

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

タグ

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by