annotate toolboxes/FullBNT-1.0.7/bnt/learning/CovMat.m @ 0:e9a9cd732c1e tip

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