跳到正文
Hub Nexus
更新

作者暂无作者认领

发现可以改进的地方?提出一个改动吧。

赞助

此页面是公开的。

MATLAB Workspace

MATLAB has a programming environment in its own and needs an area to store the variables and other program data that is stored while using the tool. MATLAB has a command window as shown, and a base workspace which is the default workspace. Functions in MATLAB also have their own workspace, and the visibility of a variable is dependent on the workspace that it resides in. If the variable is in the base workspace then it is visible to all of the scripts and functions in MATLAB, while a function's local variables are visible to that function only and are not usable outside that function.

Type this on the MATLAB Command Window

My_Var = 10

You will see

My_Var =

10

as a response, also note that there would also be an addition to the Base workspace.

(Image: ArunMKumar, CC BY-SA 4.0)

To check out what all variables are stored in the MATLAB workspace, we can use the following command.

who

This would list out all the variables currently present in the MATLAB workspace, but would not give much idea about the data types and the size of the variables, to have those in the result use this command instead

whos

By this time, i think there would be much clutter on your command window.

To clear out all the output on the command window, use this command.

clc

This WOULD NOT clear out the variables and the history. so that you would have a new clean and fresh command window.

The output of whos on my screen showed something like this

(Image: ArunMKumar, CC BY-SA 4.0)

Now, if you notice the Size is marked as 1X1, but why?
The reason for this is that in MATLAB all the data is realized as double precision arrays (well, its the way MATLAB is designed to work as it is a scientific computing tool). And so scalars like these are realized as a 1X1 array. Simple!

After all this if you think your work is done and you do not need all those variables in the MATLAB workspace now, you can relieve yourself of your Programmers baggage by using this command.

clear

This clears out any and all variables in the workspace. But if your miseries are not yet to finish and would like to remove a variable or two.

clear ....

where var1, var2, var3,.... are the variables that you want to clear, do not put the three dots in the end, that's just for description.

Where this page came from

This page was imported from Wikibooks. From “MATLAB Programming” on Wikibooks, by its contributors, under CC BY-SA 4.0. Changed here: set as a page; navigation and edit links left out; each image under its own licence, credited in its caption.

Nobody has written it yet — it is the source material at a new address, which is why search engines are asked to skip it and why no one earns from it. It is up for grabs: take it on, and it is yours to rewrite and to earn from.

收录于这些专栏MATLAB Programming

语言English

许可协议: CC BY-SA 4.0 · 改编自 en.wikibooks.org

观看次数

留言

Spinner Logo
版本: 2CC0 1.0(公有领域)
The runaway star that left the Tarantula Nebula
版本: 2CC0 1.0(公有领域)
The Eagle Nebula, seen in the infrared
版本: 2CC0 1.0(公有领域)
The Cosmic Cliffs are not cliffs
版本: 2CC0 1.0(公有领域)
The recommended targets are real, but the largest health gain is between doing nothing and doing a little. That is the part worth knowing if you are starting from nothing.
版本: 2CC0 1.0(公有领域)
Sleep is not one state but a cycle through several, each doing different work. Most sleep disorders are a failure to complete that cycle rather than a shortage of hours.
版本: 2CC0 1.0(公有领域)
Four nebulae that revealed the shape of our galaxy