Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

INTRODUCTORY MATLAB TUTORIAL

Step 5: Plot σx vs. ri, Take 3: File Input/Output

...

Scroll down to look at the example under Remarks.

Consider the following statement:

...

Wiki Markup
This will read in _\[A\]_ from the specified file. Let's test this at the command line before we add it to our program: 

Check A in the Workspace. Note that each line in the text file is interpreted as a matrix row.

...

Wiki Markup
Append the elements of _\[B\]_ to _input_data.txt_ and save the file: 

Now we need to tell MATLAB to:

  1. Read in the first two rows and assign it to A.
  2. Read in the last two rows and assign it to B.

An additional complication is that A and B have different number of columns. To handle this mess, we turn to the following nugget from the dlmread documentation:

...

Wiki Markup
\[ (2,0) \____________________\_ \]

Wiki Markup
\[_...\__\____________________\_ \]

Wiki Markup
\[(n-1,0) \_________\_ \_(n-1,m-1)\]

Wiki Markup
Once again, edit _beam4.m_. Now, use the dlmread command with the delimiter and range inputs to extract both A and B at the same time. The delimiter should be '', the range should be \[0 0 1 1\] for A and \[2 0 3 0\] for B. Remember to add your semi-colons.

...