Create a Matlab script that will load the file finc.mat and create a structure f
ID: 3801422 • Letter: C
Question
Create a Matlab script that will load the file finc.mat and create a structure from the appropriate with the following fields: • Company (string) • First_Name (string) • Last_Name (string) • Address (string) • Credit_Card_Number (Integer) • Account_Balance (Real) • Credit_Score (Real) • Transaction (Array) To the right of the field names above are the data type in parentheses. Your code should calculate and display the following: • The descriptive statistics discussed in class of the Credit Scores for each customer. • The Credit Score that is the demarcation of the top 10% of credit scores. • The full name, company, address, account balance, and credit score of the individual with the lowest credit score.
Explanation / Answer
m = matfile(filename) creates a MAT-file object, m, connected to the MAT-file named filename. The object allows you to access and change variables directly in a MAT-file, without having to load the variables into memory.
The partial loading and saving that the matfile function provides requires less memory than the load and save commands, which always operate on entire variables.
example
m = matfile(filename,'Writable',isWritable) enables or disables write access to the file.
Examples
collapse all
Load Entire Variable
Open Live Script
Load variable topo from the example file, topography.mat.
Open the example MAT-file, topography.mat.
Read the variable topo from the MAT-file.
MATLAB® loads the entire variable, topo, into the workspace.
Save Entire Variable to Existing MAT-file
Open Live Script
Generate a 20-by-20 example array, x, and save it to a MAT-file called myFile.mat.
Create a MAT-file object connected to the existing MAT-file named myFile.mat. Enable write access to the MAT-file by setting Writable to true.
Generate a 15-by-15 example array, y.
Save y to the MAT-file. Specify the variable in the MAT-file using dot notation similar to accessing fields of structure arrays.
MATLAB® adds a variable named y to the file.
Display all variables stored in the MAT-file, myFile.mat.
Load and Save Parts of Variables
Open Live Script
Access specific elements of a MAT-file variable.
Open a new MAT-file, myFile2.mat.
Save a 20-by-20 example array to part of a variable, y, in myFile2.mat. Specify the variable in the MAT-file using dot notation similar to accessing fields of structure arrays.
MATLAB® inserts the 20-by-20 array into the elements of y specified by the indices (81:100,81:100).
Read a subset of array y into a new workspace variable, z.
MATLAB reads the 10-by-10 subarray specified by the indices (85:94,85:94) from the MAT-file into workspace variable z.
Determine Size of Variables
Open Live Script
Determine the size of a variable, and then calculate the average of each column.
Open the example MAT-file, stocks.mat.
Determine the size of the variable, stocks, in stocks.mat.
Compute the average of each column of the variable stocks.