Friday, July 1, 2011

Cell array, self-defined function, and save fig

I learned a lot of important things yesterday, after spend 10 hours in front of computer playing with MatLab. Alright, here's the code I came up with.


%Created on 6/30/2011
clear all
clc
sitenumber='01';


SampleLocation=[];
AER=[];
Err=[];




%% Importing data from intermediate file
filename='whatever it is.xlsx';
D1=xlsread(filename, 'A14:C25');
D2=xlsread(filename, 'I14:K25');
D3=xlsread(filename, 'Q14:S25');
D4=xlsread(filename, 'Y14:AA25');
D5=xlsread(filename, 'AG14:AI25');
D6=xlsread(filename, 'AO14:AQ25');
D7=xlsread(filename, 'AW14:AY25');
D8=xlsread(filename, 'BE14:BG25');
D9=xlsread(filename, 'BM14:BO25');
D10=xlsread(filename, 'BU14:BW25');
D11=xlsread(filename, 'CA14:CD25');
D12=xlsread(filename, 'CJ14:CL25');
D13=xlsread(filename, 'CR14:CT25');
D14=xlsread(filename, 'CZ14:DB25');
D15=xlsread(filename, 'DH14:DJ25');
D16=xlsread(filename, 'DP14:DR25');
D17=xlsread(filename, 'DX14:DZ25');
D18=xlsread(filename, 'EF14:EH25');
DCell={D1,D2,D3,D4,D5,D6,D7,D8,D9,D10,...
    D11,D12,D13,D14,D15,D16,D17,D18}; % Put all the arrays into one big cell array so that each time I can take one cell out and use it as the function input. 


% Use each array as function input % This is a self-defined function
for k=1:18
    [AERate Error]=getDecayrate(DCell{k}); %If use DCell (k), the function won't work.
    
    SampleLocation(1,k)=k;
    AER(1,k)=AERate;
    Err(1,k)=Error;
        
    newfilename=strcat('Site_', sitenumber, '_SampleLocation_', num2str(k),'.fig');
    saveas(gcf,newfilename) % This saveas function works pretty good. The .fig file can be edited later in MatLab.
end


 Result=[SampleLocation', AER', Err'];


%The following function calculates the first-order decay rate of the tracer gas, and returns two parameters. 

function [AER Err] = getDecayrate( location)
%UNTITLED2 Summary of this function goes here
%   Detailed explanation goes here


%AER=Data-1;
TimeS=zeros(1, length(location))';
LNC1=zeros(1, length(location))';
LNC2=zeros(1, length(location))';
for i=2 : length(location)
        TimeS(i)=(location(i,1)-location(1,1))*1440/60;
end


for j=2 : length(location)
    LNC1(j)=log(location(j,2)/location(1,2));
    LNC2(j)=log(location(j,3)/location(1,3));
end


slope1=sum(TimeS.*LNC1)/sum(TimeS.^2);
slope2=sum(TimeS.*LNC2)/sum(TimeS.^2);
AER=abs((slope1+slope2)/2);
Err=abs(AER-abs(slope1));
TimeModel=0:0.01:max(TimeS);
LNC1Model=TimeModel.*slope1;
LNC2Model=TimeModel.*slope2;
plot(TimeS, LNC1, 'xr',TimeS, LNC2, 'sb', TimeModel, LNC1Model,'r', TimeModel, LNC2Model, 'b', 'MarkerSize',10, 'LineWidth', 2)
title ('Location')
xlabel('Time (hours)')
ylabel('Ln(C/C0)')
end


my-alpine and docker-compose.yml

 ``` version: '1' services:     man:       build: .       image: my-alpine:latest   ```  Dockerfile: ``` FROM alpine:latest ENV PYTH...