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

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