Data Entry in Matlab


There are several ways to get data in and out of Matlab. Input methods include:

As an important reminder ...
Beware: By default, the result of all assignment operations are printed. Appending a semicolon (;) to end of an assignment suppresses this printing. The command sequence

>> A = zeros(100,100);
>> for j = 1:100
>>    for i = 1:100
>>       A(i,j) = 1.0/(i+j-1)
>>    end
>> end
will print out approximately 50 million doubles. This is because when a single component of an array is assigned to and the semicolon is omitted, the entire array is printed - not just the changed component.
Output methods are similar to input methods. A quick and dirty way to just capture data is to use diary, which turns on a scripting capture feature. Typing diary off turns it off again. You can name the diary file as well, allowing several diaries to be captured.

A better mechanism is to use the save and load commands. By default they will save/load a binary file containing all of the variables in your current workspace - sort of a snapshot of the session. You can also save just specified variables, save to an ascii format file, etc. A good use for save is when you hit a bug while working, and cannot get around it. Save your workspace along with a note of what you were trying to do, so that it can be easily reloaded and demonstrated to me (or to Mathworks, if it is their bug!)


  • Initialized: Mon Feb 2 13:59:10 EST 2004
  • Last updated: Tue Jan 15 18:09:42 EST 2008