Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Make four files of data like the following where each file contains one column:

ID: 3543434 • Letter: M

Question

Make four files of data like the following where each file contains one column:

File1                  File2              File3                 File4

1                        23423            234                  12

4                        234                0                      -23

546                    -15                 5                      153

234                    -156               56                    -153

754                    1                    2342                0

234                    89                  -546                 234

456                    -568              13234               0

345                    -5                  -5                      165135

Import the data into matlab as a single array and tell me how many instances of the number 234 exist using a loop. Output the entire array into excel.

Now let's assume that each of these four columns represents the coefficients of a system of linear equations. What is the solution of the system of equations?

Now that the data is in an array tell me how many numbers are negative (Obviously using Matlab).

I want to know the sum, mean, and the standard deviation of the data. Do NOT use any built in matlab functions like sum(), mean(), or std(). And do not do it manually...Use the programming tools we've been working on. For example, if you just type these numbers in matlab and add them up manually you'll get no points.

Append file 1 to be (just change the specific numbers):

1

4

-2

234

754

0

456

345

Turn the original array intoa single vertical dimension (nx1) and then count the number of characters in total.

Explanation / Answer

The load command is used to load data from a file into the current workspace.

Since analyzing data is one of the more common motivations for using input output I will start with reading and writing from a spreadsheet. I cover the command line first since it is often necessary to import the data while an m-function is being evaluated.

MATLAB makes it easy to read from an Excel spreadsheet. It has the built in command "xlsread". To use the xlsread function use the syntax:

This line of code reads filename.xls (from the current directory) and places it in an identical array inside MATLAB called g. You can then manipulate the array g any way you want. Make sure that the file you choose is in the same directory were you save your M-files (usually the work directory) otherwise you get an error. You can specify the path to a file but, this can get messy.

To write data to an .xls the procedure is very similar. The xlswrite command below creates a spreadsheet called filename.xls in the current directory from the variable g:

NOTE: if you are using MATLAB 6.5 there is no "xlswrite" command (that I'm aware of). There are several ways to write to a file. The simplest way I have found is

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote