Code covered by the BSD License  

Highlights from
workspace

3.0

3.0 | 1 rating Rate this file 3 Downloads (last 30 days) File Size: 6.57 KB File ID: #23078

workspace

by Bruno Luong

 

23 Feb 2009 (Updated 27 Feb 2009)

create and manipulate variable names in the target workspace by using strings

| Watch this File

File Information
Description

Now and then people want to load a file and assign them to a variable name with a meaning that reflects the data.

Up now Matlab users have many but two choices:
- using EVAL (evil)
- put the data burried inside a structure

Here is a third choice:

ws=workspace % class constructor
datastr='data1';
ws.(datastr)=load([datastr '.txt'])
plot(data1);

% Easy? No?

I'm almost sure there will be many protests to this submission.

MATLAB release MATLAB 7.3 (R2006b)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (3)
23 Feb 2009 us

bruno, not REALLY a third choice: this snippet simply uses EVALIN in its core engine...
hence, (admittedly a lot of good work for) something that should not be supported on first place...
us

24 Feb 2009 Bruno Luong

Hi us,

Thank you for your comment. In depth, despite of your note, there are two advantages of the code and it is totally fair to compare WORKSPACE with EVAL IMHO:

First: Within the WORKSPACE methods evalin is used for the sole purpose of retrieving the value of variable(s) from the workspace. Never evalin is evaluated with the RHS (statement with '=' sign').

Second: From the user point of view, he/she does not to worry about building EVAL with full statement. Expressions are evaluated directly, and no longer through string (except for the variable name) as with EVAL.

Bruno

02 Mar 2009 Bruno Luong

Originally the WORKSPACE was developed under Matlab 2008B.
I (the author) have upgraded and tested the new version of the package (27 Jan 2009) for backward compatible to 2006B (tested under 2006B, 2007A, 2008B, and 2009A-prerelease). The workspace used the object-oriented programming (OOP) introduced officially by The Mathworks since 2008A. The file uses undocumented OOP feature and Java hashing for backward compatible.
I will be graceful if users of this package can report any eventual incompatible issue with previous versions.

Please login to add a comment or rating.
Updates
23 Feb 2009

Correct bug
New feature : workspace references with comma sign (':')

24 Feb 2009

Possibly clearing selected variables with regular expression and wildcard

27 Feb 2009

Use java containers for backward compatible
The new version run under 2006B (tested)
It also run on 2008B, 2009A
Not tested on other versions

Tag Activity for this File
Tag Applied By Date/Time
assign Bruno Luong 23 Feb 2009 12:00:26
assignin Bruno Luong 23 Feb 2009 12:00:26
eval Bruno Luong 23 Feb 2009 12:00:26
variable name Bruno Luong 23 Feb 2009 12:00:26
evalin Bruno Luong 23 Feb 2009 12:00:26
evil eval Bruno Luong 23 Feb 2009 12:00:26

Contact us at files@mathworks.com