wolffd@0: function [CovMatrix, obs, varfields] = CovMat(filename,row_cols) wolffd@0: %[CovMatrix, obs, varfields] = CovMat(filename,row_cols) wolffd@0: %% generates a Covariance Matrix from a file of data consisting of N columns of M data rows wolffd@0: %% filename string name (with path and extension) of file to open wolffd@0: %% row_cols Number_of_converstions_per_row (turns into [3 inf]) wolffd@0: %% Return wolffd@0: %% CovMatrix Covariance matrix wolffd@0: %% obs Number of observations read in wolffd@0: %% varfields Labels of the variables see filename structure below wolffd@0: %% wolffd@0: %% Filename structure: wolffd@0: %% Comma separated, starting with the variable labels, then the data in rows. wolffd@0: %% filename test.txt consists of: wolffd@0: %% wolffd@0: %% Earthquake,Burglar,Radio,Alarm,Call wolffd@0: %% 1,2,3,4,5 wolffd@0: %% 11,22,33,44,55 wolffd@0: %% . . . wolffd@0: %% wolffd@0: %% Example call: wolffd@0: %% [cvmat numdat lables] = CovMat('test.txt',5); wolffd@0: %% wolffd@0: %% Returns Covariance matrix, number of date rows and variable field names wolffd@0: %% Gary R. Bradski 7/2002 wolffd@0: wolffd@0: fmtstr = '%f'; wolffd@0: for i = 2:row_cols wolffd@0: fmtstr = strcat(fmtstr,',%f'); wolffd@0: end wolffd@0: wolffd@0: %% load data wolffd@0: fidCov = fopen(filename,'r'); wolffd@0: wolffd@0: varfields = fgetl(fidCov); wolffd@0: Corx = fscanf(fidCov,fmtstr,[row_cols inf]); wolffd@0: Corx= Corx'; wolffd@0: [obs bla] = size(Corx); wolffd@0: CovMatrix = cov(Corx); wolffd@0: fclose(fidCov);