フィルターのクリア

comparing rows in matrices

1 回表示 (過去 30 日間)
Tor Fredrik Hove
Tor Fredrik Hove 2012 年 5 月 8 日
function lottonumbers = draw_lottonumbers(draws, balls,rows)
% A function that draws 'draws' random integers without replacement
between 1 and
% 'balls', i.e. a random lotto sequence
% INPUT PARAMETERS
% draws: # of balls drawn (in norwegian lotto this is 7)
% balls: # of balls, i.e. # of possible numbers (in norwegian
lotto this is 34)
% rows: # of lottorows (in norwegian lotto this is normally 10)
% OUTPUT PARAMETERS
% lottonumbers: a matrix with 'rows' rows, where the rows are the
% lotto-combinations you play
lottonumbers = zeros(rows,draws);
for i=1:rows
temp_combination = randsample(balls,draws,'false');
% draw 'draws' integers between 1 and 'balls'
lottonumbers(i,:) = sort(temp_combination);
% sort the drawn lottosequence in ascending order
end
using function above:
function thrtyfoinrow=drawlotto(v)
thrtyfoinrow=0;
draw_lottonumbers(7,34,v)
winner=rand(1,7);
winner=ceil(winner);
for i=1:v
if winner==lottonumbers(i,:)
for j=1:v
if winner(j)==34
thrtyfoinrow=thrtyfoinrow+1;
end
end
end
end
I get error in
if winner==lottonumbers(i,:)
I guess my comparing is bad?
  2 件のコメント
Oleg Komarov
Oleg Komarov 2012 年 5 月 8 日
What error do you get?
Daniel Shub
Daniel Shub 2012 年 5 月 8 日
My guess is the error is related to the fact that winner is 1x7 and not a scalar.

サインインしてコメントする。

回答 (1 件)

Daniel Shub
Daniel Shub 2012 年 5 月 8 日
You might want to use
doc isequal
or
all(winner == lottonumber(i,:))

Community Treasure Hunt

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

Start Hunting!

Translated by