如何在MATLAB中用标量划分矩阵?

时间:2013-03-31 10:52:43

标签: matlab matrix division scalar

只是有一些问题使用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';

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

1 个答案:

答案 0 :(得分: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