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

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

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개)

카테고리

도움말 센터File Exchange에서 Logical에 대해 자세히 알아보기

질문:

2017년 1월 11일

댓글:

2017년 1월 11일

Community Treasure Hunt

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

Start Hunting!

Translated by