How to solve "Matrix dimensions must agree error" for this function?

2 次查看(过去 30 天)
Matrix Dimensions didn't agree in a function. Please tell me the meaning of unique function. While i try to debug the function by setting breakpoints, the trblock cell array receives value only in the 1x6th location, it actually has 1x8 cell array, all other locations are empty. and the tr_block_diag_mat has 15x15 single value
my values are tr_descr = 114x98, tt_descr = 112x98, tr_label = 114x1, tt_label = 112x1, tottrainlabel = 231x1
Error in ProCRC (line 34) tr_sym_mat = (gamma * (class_num - 2) + 1) * (tr_descr' * tr_descr) + gamma * tr_block_diag_mat + lambda * eye(size(tr_descr, 2));
%%Function
function Alpha = ProCRC(data, params)
tr_descr = data.tr_descr;
tt_descr = data.tt_descr;
tr_label = data.tr_label;
gamma = params.gamma;
lambda = params.lambda;
class_num = params.class_num;
tt_num = length(data.tt_label);
model_type = params.model_type;
tr_blocks = cell(1, class_num);
for ci = 1: class_num
tr_blocks{ci} = tr_descr(:,tr_label == ci)' * tr_descr(:,tr_label == ci);
end
tr_block_diag_mat = blkdiag(tr_blocks{:});
tr_sym_mat = (gamma * (class_num - 2) + 1) * (tr_descr' * tr_descr) + gamma * tr_block_diag_mat + lambda * eye(size(tr_descr, 2));
%%Main program
data.tr_descr = F_train';
data.tt_descr = F_test';
data.tr_label = otrainlabel;
data.tt_label = otestlabel';
dataset.label = tottrainlabel;
% class_num = length(unique(dataset.label));
class_num = length(unique(data.tr_label'));
params.gamma = [1e-2];
params.lambda = [1e-0];
params.class_num = class_num;
params.dataset_name = 'Action';
params.model_type = 'NN';
Alpha = ProCRC(data, params);
  1 个评论
KSSV
KSSV 2017-1-11
Problem is here in this line:
tr_blocks{ci} = tr_descr(:,tr_label == ci)' * tr_descr(:,tr_label == ci);
This is resulting into a empty matrix and creating problem. check that line once.

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Gamma Functions 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by