MATLAB Answers

function variables not saved to workspace

15 views (last 30 days)
Qiana Curcuru
Qiana Curcuru on 10 Mar 2020
Commented: Star Strider on 14 Oct 2021 at 21:25
Hi,
I define variables in one function and want to pass them off to another function. If I stop the function right before the function ends (at y), x and y are in my workspace, but once the function ends, x and y are gone, and not saved to my workspace.
function [x,y]=myfunc()
x=2;
y=3;
end

Accepted Answer

Star Strider
Star Strider on 10 Mar 2020
Call the function as:
[x,y]=myfunc()
and both should be in your workspace.
  4 Comments

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!

Translated by