Info

この質問は閉じられています。 編集または回答するには再度開いてください。

determining if a value repeats within a vector

2 ビュー (過去 30 日間)
William Marble
William Marble 2019 年 4 月 24 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
I am trying to determine the value of an integer that repeats 3 times within a vector of 5 elements.
I am trying to code Yahtzee with basic MATLAB knowledge, and am stuck.
An example is a vector of [ 1, 2, 3, 1, 1] and I want to be able to verify that there are 3 ones in the vector.
  2 件のコメント
per isakson
per isakson 2019 年 4 月 24 日
Try
>> val =[ 1, 2, 3, 1, 1];
>> [N,edges] = histcounts( val, [unique(val),inf] )
N =
3 1 1
edges =
1 2 3 Inf
>> edges( N==3 )
ans =
1
>>
William Marble
William Marble 2019 年 4 月 24 日
Thanks!

回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by