How do I use a variable assigned in one function to call another function?
Show older comments
I am trying something similar to
global a
a = 5
global b
b = 10
name1(a, b)
name2(x, b)
function[x] = name1(a, b)
global a
global b
x = a + b
end
function[y] = name2(c, d)
global b
y = x + b
end
Do I need to make variable x global inside of a function or something else? I tried setting it global inside and outside of the function and I still couldn't call function y with variable x. What am I doing wrong?
Accepted Answer
More Answers (1)
The code does not global variables at all
a = 5;
b = 10;
x = name1(a,b)
y = name2(x,b)
function out = name1(var1,var2)
out = var1 + var2;
end
function out = name2(var1,var2)
out = var1 + var2;
end
Categories
Find more on Logical 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!