1

只是在使用 MATLAB 将矩阵的所有值除以标量时遇到一些问题。

我的代码看起来像,

ncol = length(indpic(1,:)); % ncol = 32
row0 = sum(indpic == 0,2); % 161 * 1 matrix
rowprob0 = 'row0' / 'ncol';

但最后一行一直导致错误。我尝试了以下方法,但它们都没有工作,

rowprob0 = 'row0' ./ 'ncol';
rowprob0 = 'row0' * (1/('ncol'))';
rowprob0 = 'row0' .* (1/('ncol'))';

我也尝试过解决这个问题,但效果更差,

ncol = length(indpic(1,:)); % ncol = 32
row0 = sum(indpic == 0,2); % 161 * 1 matrix
id_ncol_1 = eye(ncol,ncol);
id_ncol = (id_ncol_1).*(ncol);
rowprob0 = 'row0' / 'id_ncol';

如果有人可以帮助我,那将不胜感激:) 提前欢呼

4

1 回答 1

0

你为什么写row0ncol引号?只需除以 row0得到ncol结果。

ncol = length(indpic(1,:)); % ncol = 32
row0 = sum(indpic == 0,2); % 161 * 1 matrix
rowprob0 = row0/ncol  %or row0./ncol, doesn't make a difference when dividing by a scalar
于 2013-03-31T11:25:18.290 回答