Variables in function are not stored in workspace
Show older comments
When I run the following code, I cant access g1 and g2. How can I get g1 and g2 to be stored in the workspaceso that I can access it later?
function g = helpme(x)
g=0;
syms f;
for i=1:length(x)
if length(x)~=1
g= cumsum(x);
[c,index] = min(abs(g-sum(x)/2));
if(i<=index)
f(:,i) = zeros(1);
else
f(:,i) = ones(1);
end
g1 = x(1,1:index)
g2 = x(1,index + 1:length(x))
end
end
end
commandwindow
ss=[27 24 10 9 9 9 6 4 3 3 3 3 3];
hh=helpme(ss)
Accepted Answer
More Answers (1)
David Hill
on 5 Apr 2020
0 votes
Click on the line in the function where you want to place a breakpoint. Execute the function. The function will stop at the breakpoint and your variables will be in the workspace.
Categories
Find more on Loops and Conditional Statements 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!