How to solve "Matrix dimensions must agree error" for this function?
1 回表示 (過去 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
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/159696/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/159697/image.png)
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
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 Center および File Exchange で Gamma Functions についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!