Wednesday, June 1, 2011

simple data matching by using dataset arrays

Task : There are two Excel files, one contains the sample number and the time of sampling while the other contains the analysis results of each sample. Because the samples were taken in a chronicle order and were analysed in random order, it is kind of time consuming to manually find out each sample's result and put them into one file, especially when dealing with thousands of samples.

Here's a short code I wrote to do this:

% This program search the bag numbers and put the corresponding
% concentration values into the data file.
%% initialization
clear all;
clc;


%% import data
dataf=dataset('xlsfile','back.xls'); %aisle files from field test
concf=dataset('xlsfile','concentration.xls'); %concentration readings from autoTrac


%% determine dataset array size
datafL=length(dataf);
concfL=length(concf);


%% search and match
for i=1 : datafL
 for j= 1 : concfL-1
     
               if (  char(dataf.BagNumber(i))==char(concf.BagNumber(j))  )
                            dataf.Concentration1(i)=concf.Concentration(j);
                            dataf.Concentration2(i)=concf.Concentration(j+1);
                             break
               end
 end
end


%% Output data
export(dataf, 'xlsfile', 'Processed bag files-back.xls')

The dataset array is very power at handling different type of data, including numbers, strings, and even matrix.
To write a dataset array to an Excel file, I need to use export function instead of xlswrite.

No comments:

Post a Comment

Any comments?

my-alpine and docker-compose.yml

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