Beat deadlines for urgent projects with our Matlab assignment help Need to finish your Matlab assignment fast? Connect with our Matlab homework helpers. Contact us right away for timely Matlab assignment help Usually, when professors issue Matlab assignments, they give students enough time to c...

Data Manipulation

#### Data Analysis

Published : 23-02-2018

In this assignment, you are required to find some data from online resources and import it into Matlab. Explain your data briefly including the columns you are interested in. If the data contains too many columns, identify and list the columns you will be working on. Use Matlab to clean and organize your data. Next, try to comprehend your data for example, by measuring the variance, max, mean, etc. of the columns you are interested in or by plotting histograms, pie charts, 2-d plots, etc. Explain these plots and your findings. Finally, find the relationship between the different columns you are interested in and perform any other analysis you find helpful in manipulating and understanding your data.

```
clear all,
close all,
clc
% parameters for the lorenz model
s = 10.;
b = 8/3;
r = 28.;
%s=input('Press 1 to change initial conditon and 2 to change stepsize')
% numerical parameters
% Chaniging the step size by adding 0.0000001
dt = 1e-2+0.0000001; % time step
tend = 20; % time interval length
tdim = tend/dt; % number of time steps to compute
% initial values 'Changing initial conditons'
% You can note the figures of x,y, z, as well as
% The 3D figure, you will see that a small change will lead to
% More starting points before comoing to equiliruim points
% You can use your own explanation which could be better then mine
% Based on your course of cours
% The intial values are: x0=-7.3196, y0=0.9739, z0=32.595
xyz(1,1)=-7.3196; % x start value
xyz(1,2)= 0.9739; % y start value
xyz(1,3)= 32.595; % z start value
% main loop integration of differential eq.
for it=2:tdim
xyz(it,1) = xyz(it-1,1) +dt*(-s*xyz(it-1,1)+s*xyz(it-1,2));
xyz(it,2) = xyz(it-1,2) +dt*(-xyz(it-1,1)*xyz(it-1,3)+r*xyz(it-1,1)-xyz(it-1,2));
xyz(it,3) = xyz(it-1,3) +dt*(xyz(it-1,1)*xyz(it-1,2)-b*xyz(it-1,3));
end
time=(1:tdim)*dt;
% example plot of time series the variable X
figure(),
plot(time, xyz(:,1))
title('time series of X')
xlabel('time [non-dimensional]')
ylabel('X [non-dimensional]')
figure(),
plot(time, xyz(:,2))
title('time series of Y')
xlabel('time [non-dimensional]')
ylabel('Y [non-dimensional]')
figure(),
plot(time, xyz(:,3))
title('time series of Z')
xlabel('time [non-dimensional]')
ylabel('Z [non-dimensional]')
figure(),
plot3(xyz(:,1),xyz(:,2),xyz(:,3)); grid on
% The time at the equilirbuim points are:
[px,rx]=find(xyz(:,1)
```

```
function ButtonPushed_TASK1(btn, flag, LocationID, Days, Ice, DayID)
% global DayID
if flag == 1
DayID = find(Days == str2double(btn.Text));
% Show dialog with LocationID
Nl = length(LocationID);
fig = uifigure('Name', 'Select Day', 'Position', [50, 100, 200, 200]);
for i = 1:Nl
uibutton(fig, 'Text', LocationID(i), 'Position', [50, (Nl-i+1)*30, 100, 22], 'ButtonPushedFcn', @(btn, event) ButtonPushed_TASK1(btn, 2, LocationID, Days, Ice, DayID));
end
else
% get index
location_id = find(LocationID == btn.Text);
ice = Ice(DayID, location_id);
fprintf("On day %s, at location %s, the ice thickness wass %s [m]\n", num2str(DayID), LocationID(location_id), num2str(ice));
uiresume
end
end
function ButtonPushed_TASK5(btn, LocationID, Days, Ice)
% get index
location_idx = find(LocationID == btn.Text);
figure
plot(Days, Ice(:, location_idx), 'ro');
xlabel('Time [days]');
ylabel('Ice Thickness [m]');
title(strcat(['Ice Thickness at Location ', btn.Text, ' over time']));
grid on
end
function [out1, out2, out3, out4, out5] = DataStats(Days, LocationID, Ice)
% Get number of measurements
out1 = size(Ice,1)*size(Ice,2); % number of rows*cols
% Overall average measurement
out2 = mean(mean(Ice));
% Maximum overall all measurement and its location
[out3, out4] = max(Ice(:));
% Day at which max value was found
out5 = -1;
k = 1;
for i = 1:size(Ice,1)
for j = 1:size(Ice,2)
if k == out4
out5 = Days(i);
out4 = LocationID(j);
return;
end
k = k + 1;
end
end
end
clc, clear all, close all
load MA2_data.mat
%% Task 1
fig = uifigure('Name', 'Select Day', 'Position', [50, 100, 200, 550]);
Nb = length(Days);
for i = 1:Nb
uibutton(fig, 'Text', num2str(Days(i)), 'Position', [50, (Nb-i+1)*30, 100, 22], 'ButtonPushedFcn', @(btn, event) ButtonPushed_TASK1(btn, 1, LocationID, Days, Ice, 0));
end
uiwait
%% Task 2
fprintf("\n");
new_day = max(Days)+3; % 3 days after the last record
thickness_vec = input("Enter ice thickness data at all locations, 3 days after the last recorded day (as a vector): ");
new_locid = input("Enter the location ID for the newly discovered location: ", 's');
new_ice = input("Enter the ice thickness on the new day, at the new location: ");
% update data
LocationID = [LocationID, new_locid]; % update LocationID
Days = [Days;new_day]; % update the Days data
% Append the new data for current locations
Ice = [Ice;thickness_vec];
% Now, append a new column for the new location. For previous day, the data
% will be zero since there was no record for that location
Ice(:,end+1) = zeros(size(Ice,1), 1);
% Now, append new data for new location
Ice(end, end) = new_ice;
save("MA2_Task2.mat", 'Days', 'LocationID', 'Ice');
fprintf("\n");
fprintf("Days, LocationID and Ice have been updated. See 'MA2_Task2.mat'\n");
% Task 3
[N, Avg, Max, LocMax, DayMax] = DataStats(Days, LocationID, Ice);
fprintf("\n");
fprintf("A total of %s measurements have been taken.\n", num2str(N));
fprintf("The overall average ice thickness is %.3f [m].\n", Avg);
fprintf("The maximum overall ice thickness is %.3f [m], which ocurrs on Day %s at Location %s.\n", Max, DayMax, LocMax);
% Task 4
fprintf("\n");
perc = input("Enter the projected percent reduction rate (0-100%): ");
IceNew = Projection(perc, Ice);
% Save to Excel
csvwrite("MA2_Task5.csv", IceNew);
fprintf("Projected ice thicknesses calculated. See MA2_Task4.csv.\n");
%% Task 5
fig = uifigure('Name', 'Select Location', 'Position', [50, 100, 200, 250]);
Nl = length(LocationID);
for i = 1:Nl
uibutton(fig, 'Text', LocationID(i), 'Position', [50, (Nl-i+1)*30, 100, 22], 'ButtonPushedFcn', @(btn, event) ButtonPushed_TASK5(btn, LocationID, Days, Ice));
end
function out1 = Projection(in1, in2)
% get final row
row = in2(end,:);
% Reduce
row = row.*(1-in1/100);
% Append value to the data
out1 = in2;
out1 = [out1;row];
end
```