Question

just having some issues dividing all the values of a matrix by a scalar using MATLAB.

My code looked like,

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

But the last line kept causing errors. I tried the following, but none of them worked either,

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

I also attempted mucking around with this, but to even less avail,

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';

If anyone can help me out, that'd be greatly appreciated :) cheers in advance

Was it helpful?

Solution

Why are you writing row0 and ncol in quotes? Just divide row0 by ncol to get the result.

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
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top