필터 지우기
필터 지우기

i have a important question!! ( function "randfixedsum" )

조회 수: 3 (최근 30일)
Brian Kim
Brian Kim 2017년 3월 28일
답변: Roger Stafford 2017년 3월 28일
i successd in create matrix 'x' from "randfixedsum"
in here, 'x' is formed 'double'. and 'x' can recreate as integer by using "round", "ceil", or "floor"
by the way,
how to create 'x' by way for 'integer' by itself?

답변 (2개)

Roger Stafford
Roger Stafford 2017년 3월 28일
I think you might prefer to use the following code rather than using randfixedsum and rounding to integers:
function R = randfixedsumint(m,n,S);
% This generates an m by n array R. Each row will sum to S, and
% all elements are all non-negative integers. The probabilities
% of each possible set of row elements are all equal.
% RAS - Mar. 4, 2017
if ceil(m)~=m|ceil(n)~=n|ceil(S)~=S|m<1|n<1|S<0
error('Improper arguments')
else
P = ones(S+1,n);
for in = n-1:-1:1
P(:,in) = cumsum(P(:,in+1));
end
R = zeros(m,n);
for im = 1:m
s = S;
for in = 1:n
R(im,in) = sum(P(s+1,in)*rand<=P(1:s,in));
s = s-R(im,in);
end
end
end
return

KSSV
KSSV 2017년 3월 28일
doc uint8
  댓글 수: 2
Brian Kim
Brian Kim 2017년 3월 28일
where apply that?
KSSV
KSSV 2017년 3월 28일
편집: KSSV 2017년 3월 28일
uint8 covers double to int.
x_int = uint8(x) ;

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by