23.12.2012 Views

MATLAB Function Reference Volume 1: A - E - Bad Request

MATLAB Function Reference Volume 1: A - E - Bad Request

MATLAB Function Reference Volume 1: A - E - Bad Request

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

2assignin<br />

Purpose Assign a value to a workspace variable<br />

Syntax assignin(ws,'var',val)<br />

assignin<br />

Description assignin(ws,'var',val) assigns the value val to the variable var in the<br />

workspace ws. var is created if it doesn’t exist. ws can have a value of 'base' or<br />

'caller' to denote the <strong>MATLAB</strong> base workspace or the workspace of the caller<br />

function.<br />

The assignin function is particularly useful for these tasks:<br />

• Exporting data from a function to the <strong>MATLAB</strong> workspace<br />

• Within a function, changing the value of a variable that is defined in the<br />

workspace of the caller function (such as a variable in the function argument<br />

list)<br />

Remarks The <strong>MATLAB</strong> base workspace is the workspace that is seen from the <strong>MATLAB</strong><br />

command line (when not in the debugger). The caller workspace is the<br />

workspace of the function that called the M-file. Note the base and caller<br />

workspaces are equivalent in the context of an M-file that is invoked from the<br />

<strong>MATLAB</strong> command line.<br />

Examples This example creates a dialog box for the image display function, prompting a<br />

user for an image name and a colormap name. The assignin function is used<br />

to export the user–entered values to the <strong>MATLAB</strong> workspace variables imfile<br />

and cmap.<br />

prompt = {'Enter image name:','Enter colormap name:'};<br />

title = 'Image display - assignin example';<br />

lines = 1;<br />

def = {'my_image','hsv'};<br />

answer = inputdlg(prompt,title,lines,def);<br />

assignin('base','imfile',answer{1});<br />

assignin('base','cmap',answer{2});<br />

2-63

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!