资源简介
典型相关分析 源代码 Matlab的程序
代码片段和文件信息
function [CV1CV2rhov1v2s11s22s12] = cancorr(fname1fname2 ...
nrowsncolsnvar1nvar2varargin)
% [CV1CV2rhov1v2s11s22s12] = cancorr(fname1fname2 ...
% nrowsncolsnvar1nvar2varargin)
%
% CANCORR - canonical correlation analysis
%
% Input
% fname1 - file name of multivariate band sequential byte float32 or int16 input image
% number one
% fname2 - file name of multivariate band sequential byte float32 or int16 input image
% number two
% nrows - number of rows in input image number one
% ncols - number of columns in input image number one
% nvars1 - number of variables or bands or channels in input image number one
% nvars2 - number of variables or bands or channels in input image number two
% fnameo1 - outout file name for CV1 BSQ float32 image (optio-
% fnameo2 - outout file name for CV2 BSQ float32 image nal)
%
% If fnameo1 occurs so must fnameo2.
%
% Output
% the canonical variates (CV1 and CV2)
% the canonical correlations (rho)
% the eigenvectors (v1 and v2) normed to give CVs unit variance and
% the relevant (variance-)covariance matrices.
%
% Output arrays CV1 and CV2 consist of transposed images must be viewed with e.g.
% imshow(reshape(CV1(::1)ncolsnrows)‘[-3 3])
%
% If disk output is requested a primitive .hdr file for the output file is written;
% (a full ENVI or another header file must be constructed manually).
% (c) Copyright 2005
% Allan Aasbjerg Nielsen
% aa@imm.dtu.dk www.imm.dtu.dk/~aa
% 15 Feb 2005
if nargin<6 error(‘Not enough input arguments.‘); end
if nargin>8 error(‘Too many input arguments.‘); end
if ~ischar(fname1) error(‘fname1 should be a char string‘); end
if ~ischar(fname2) error(‘fname2 should be a char string‘); end
if nargin==8
fnameo1 = varargin{1};
if ~ischar(fnameo1) error(‘fnameo1 should be a char string‘); end
fnameo2 = varargin{2};
if ~ischar(fnameo2) error(‘fnameo2 should be a char string‘); end
end
if nvar2>nvar1
error(‘input with highest number of variables must be first set‘);
end
% open as byte (uint8) image if unsuccesful open as float32 or int16
fid1 = fopen(fname1‘r‘);
if fid1==-1 error(strcat(fname1‘ not found‘)); end
[xcount1] = fread(fid1‘uint8‘);
fclose(fid1);
if count1~=(nrows*ncols*nvar1)
warning(‘data in fname1 do not match nrows ncols nvars for uint8 try float32‘);
fid1 = fopen(fname1‘r‘);
if fid1==-1 error(strcat(fname1‘ not found‘)); end
[xcount1] = fread(fid1‘float32‘);
fclose(fid1);
if count1~=(nrows*ncols*nvar1)
warning(‘data in fname1 do not match nrows ncols nvars for float32 try int16‘);
fid1 = fopen(fname1‘r‘);
if fid1==-1 error(strcat(fname1‘ not found‘)); end
[xcount1] = fread(fid1‘int16‘);
fclose(fid1);
if count1~=(nrows*ncols*nvar1)
error(‘data in fname1 do not match nrows ncols nvars for int16 either‘);
end
end
end
fid2 = fopen(fname2‘r‘);
if fid2==-1 er
评论
共有 条评论