annotate _FullBNT/BNT/learning/CovMat.m @ 9:4ea6619cb3f5 tip

removed log files
author matthiasm
date Fri, 11 Apr 2014 15:55:11 +0100
parents b5b38998ef3b
children
rev   line source
matthiasm@8 1 function [CovMatrix, obs, varfields] = CovMat(filename,row_cols)
matthiasm@8 2 %[CovMatrix, obs, varfields] = CovMat(filename,row_cols)
matthiasm@8 3 %% generates a Covariance Matrix from a file of data consisting of N columns of M data rows
matthiasm@8 4 %% filename string name (with path and extension) of file to open
matthiasm@8 5 %% row_cols Number_of_converstions_per_row (turns into [3 inf])
matthiasm@8 6 %% Return
matthiasm@8 7 %% CovMatrix Covariance matrix
matthiasm@8 8 %% obs Number of observations read in
matthiasm@8 9 %% varfields Labels of the variables see filename structure below
matthiasm@8 10 %%
matthiasm@8 11 %% Filename structure:
matthiasm@8 12 %% Comma separated, starting with the variable labels, then the data in rows.
matthiasm@8 13 %% filename test.txt consists of:
matthiasm@8 14 %%
matthiasm@8 15 %% Earthquake,Burglar,Radio,Alarm,Call
matthiasm@8 16 %% 1,2,3,4,5
matthiasm@8 17 %% 11,22,33,44,55
matthiasm@8 18 %% . . .
matthiasm@8 19 %%
matthiasm@8 20 %% Example call:
matthiasm@8 21 %% [cvmat numdat lables] = CovMat('test.txt',5);
matthiasm@8 22 %%
matthiasm@8 23 %% Returns Covariance matrix, number of date rows and variable field names
matthiasm@8 24 %% Gary R. Bradski 7/2002
matthiasm@8 25
matthiasm@8 26 fmtstr = '%f';
matthiasm@8 27 for i = 2:row_cols
matthiasm@8 28 fmtstr = strcat(fmtstr,',%f');
matthiasm@8 29 end
matthiasm@8 30
matthiasm@8 31 %% load data
matthiasm@8 32 fidCov = fopen(filename,'r');
matthiasm@8 33
matthiasm@8 34 varfields = fgetl(fidCov);
matthiasm@8 35 Corx = fscanf(fidCov,fmtstr,[row_cols inf]);
matthiasm@8 36 Corx= Corx';
matthiasm@8 37 [obs bla] = size(Corx);
matthiasm@8 38 CovMatrix = cov(Corx);
matthiasm@8 39 fclose(fidCov);