qq_43327800 2019-01-05 18:39 采纳率: 14.3%

# MATLAB 索引超出矩阵维度。

``````function [acc,G,Cls] = GFK(X_src,Y_src,X_tar,Y_tar,dim)
Ps = pca(X_src);
Pt = pca(X_tar);
G = GFK_core([Ps,null(Ps')], Pt(:,1:dim));
[Cls, acc] = my_kernel_knn(G, X_src, Y_src, X_tar, Y_tar);
end
function G = GFK_core(Q,Pt)

N = size(Q,2); %
dim = size(Pt,2);

% compute the principal angles
QPt = Q' * Pt;
[V1,V2,V,Gam,Sig] = gsvd(QPt(1:dim,:), QPt(dim+1:end,:));
V2 = -V2;
theta = real(acos(diag(Gam))); % theta is real in theory. Imaginary part is due to the computation issue.

% compute the geodesic flow kernel
eps = 1e-20;
B1 = 0.5.*diag(1+sin(2*theta)./2./max(theta,eps));
B2 = 0.5.*diag((-1+cos(2*theta))./2./max(theta,eps));
B3 = B2;
B4 = 0.5.*diag(1-sin(2*theta)./2./max(theta,eps));
G = Q * [V1, zeros(dim,N-dim); zeros(N-dim,dim), V2] ...
* [B1,B2,zeros(dim,N-2*dim);B3,B4,zeros(dim,N-2*dim);zeros(N-2*dim,N)]...
* [V1, zeros(dim,N-dim); zeros(N-dim,dim), V2]' * Q';
end
``````

• 写回答

#### 2条回答默认 最新

• qq_43327800 2019-01-06 10:29
关注

刚刚解决了，MATLAB里面我加了drtoolbox的降维包，并且修改了pathdef.m的文件，然后就不能用的，原因尚不清楚

本回答被题主选为最佳回答 , 对您是否有帮助呢?
评论

#### 悬赏问题

• ¥30 电脑误删了手机的照片怎么恢复？
• ¥15 (标签-python|关键词-char)
• ¥15 python+selenium，在新增时弹出了一个输入框
• ¥15 苹果验机结果的api接口哪里有？？单次调用1毛钱及以下。
• ¥20 学生成绩管理系统设计
• ¥15 来一个cc穿盾脚本开发者
• ¥15 CST2023安装报错