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