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

3 vues (au cours des 30 derniers jours)
arun
arun le 11 Jan 2017
Commenté : KSSV le 11 Jan 2017
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 commentaire
KSSV
KSSV le 11 Jan 2017
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.

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur Resizing and Reshaping Matrices dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by