How to save a particular value onto workspace from Matlab function? -
How to save a particular value onto workspace from Matlab function? -
i have m file, contains several files , understand when using functions, variables used within functions not saved workspace in matlab. need save 1 single variables within matlab. ways go doing this?
here 2 ways can save variable in base of operations workspace, i.e. using assignin or setappdata along getappdata
let's create dummy function test (do not name assignin cause trouble):
function test_assignin(~) %// dummy function clear clc =rand(10); assignin('base','ainworkspace',a); %/ assign variable (local function) variable named 'ainworkspace' in 'base' workspace, can access after running function. b = a/2; %// generate other variable setappdata(0,'b',b); %// utilize setappdata create variable available base of operations workspace (hence 0 @ beginning), , in command window utilize getappdata. (see below). end and if want access b in workspace, can utilize getappdata so:
binworkspace = getappdata(0,'b') %// utilize same name in function/call setappdata. note setappdata/getappdata quite useful when making guis in phone call external functions; allows share info between callbacks.
hope helps!
matlab
Comments
Post a Comment