How do I declare a variable in the MATLAB workspace from a MATLAB function?
Show older comments
I wrote a function that provides some variables to Simulink. I have declared them global, so Simulink could see them. But I have to declare them at the prompt and I am unable to declare them in the function because Simulink does not see them.
Accepted Answer
More Answers (1)
Gaganjyoti Baishya
on 20 Jun 2020
0 votes
Hi,
You can easily add variables in base from function using assignin.
function myFunc(a,b)
x=3;
assignin('base','myVar',x);
end
assignin declares the varibale myVar with value of 3.
Categories
Find more on Workspace Variables and MAT Files in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!