...
Wiki Markup |
---|
Read in \[A\] from a File |
Wiki Markup |
---|
Instead of specifying _\[A\]_ within the program, let's give the user the option of reading it in from a text file called, say, _input_data.txt_. |
Wiki Markup |
---|
Create a text file called _input_data.txt_ in your working directory with the elements of _\[A\]_, each row being on a separate line: !input_data.jpg!
Keep in mind that we have used whitespace to delimit (i.e. differentiate) the different numbers. We'll read in this data using the _dlmread_ command. Check the documentation by searching the help for *dlmread*. |
Scroll down to look at the example under Remarks.
Consider the following statement:
A=dlmread('input_data.txt')
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.
We'll create a new program called beam4.m starting from beam3.m. Select beam3.m in the Editor. Select
Editor > File > Save As
Enter beam4.m
for filename. Confirm that you are editing beam4.m. Comment out the original A specification statement and replace it with the above statement using dlmread. Add a semi-colon at the end of the statement.
Save beam4.m. Run it from the command line.
...
Widget Connector | ||||||
---|---|---|---|---|---|---|
|
Wiki Markup |
---|
Read in \[B\] from a File |
...