Archives for July 7, 2015

REThink Day 6, Learning MATLAB

 

Today I spent the day learning as much as I could in MATLAB. I went through the built-in tutorials, and ended up figuring a lot of the commands out. Take a look at the above image- it’s for 3 different fake patients. The first two are from sample data, while the third is the data I made up for myself. Here’s the Strucdem.m file that I edited:

%% Create a Structure Array
% This example shows how to create a structure array. A structure is a data
% type that groups related data using data containers called fields. Each
% field can contain data of any type or size.
%
% Copyright 1984-2011 The MathWorks, Inc.
%%
% Store a patient record in a scalar structure with fields |name|,
% |billing|, and |test|.
%
% <<strucdem_img01.png>>
%

patient(1).name = ‘John Doe’;
patient(1).billing = 127.00;
patient(1).test = [79, 75, 73; 180, 178, 177.5; 220, 210, 205];
patient

%%
% Add records for other patients to the array by including subscripts after
% the array name.
%
% <<strucdem_img02.png>>
%

patient(2).name = ‘Ann Lane’;
patient(2).billing = 28.50;
patient(2).test = [68, 70, 68; 118, 118, 119; 172, 170, 169];
patient

patient(3).name = ‘Jason DeFuria’;
patient(3).billing = 5000.00;
patient(3).test = [120, 50, 80; 90, 178, 20; 220, 210, 205];
patient
%%
% Each patient record in the array is a structure of class |struct|. An
% array of structures is often referred to as a struct array. Like other
% MATLAB arrays, a struct array can have any dimensions.
%
% A struct array has the following properties:
%
% * All structs in the array have the same number of fields.
% * All structs have the same field names.
% * Fields of the same name in different structs can contain different
% types or sizes of data.
%
% Any unspecified fields for new structs in the array contain empty
% arrays.

patient(4).name = ‘New Name’;
patient(4)

%%
% Access data in the structure array to find how much the first patient
% owes, and to create a bar graph of his test results.
figure
amount_due = patient(1).billing
bar(patient(1).test)
title([‘Test Results for ‘, patient(1).name])
figure
amount_due = patient(2).billing
bar(patient(2).test)
title([‘Test Results for ‘, patient(2).name])
figure
amount_due = patient(3).billing
bar(patient(3).test)
title([‘Test Results for ‘, patient(3).name])
displayEndOfDemoMessage(mfilename)

I did a lot of learning in the program itself, but this is a short post because it’s hard to translate that learning into words here.