MATLAB Answers

Given 2 red beads, 2 blue beads, 1 yellow bead, and 1 green bead, how many different necklaces can be made?

4 ビュー (過去 30 日間)
SammyJoe
SammyJoe 2019 年 10 月 18 日
Commented: Bjorn Gustavsson 2019 年 10 月 18 日
I need a matlab code that will determine the answer (the answer is given as 16 and I keep getting 30). Flips and circular shifts need to be taken out as well using loops

  0 件のコメント

サインイン to comment.

件の回答 (1)

Bjorn Gustavsson
Bjorn Gustavsson 2019 年 10 月 18 日
Why not just remove the non-unique necklaces? See the help and documentation for unique for how to do this.
HTH

  4 件のコメント

表示 1 件の古いコメント
Image Analyst
Image Analyst 2019 年 10 月 18 日
Hint: your "c" is not a matrix since it just gets overwritten on every iteration. Try (untested)
for k = 1 : size(p2, 1)
thisRow = p2(km :);
c(k, :) = circshift(thisRow, k);
end
SammyJoe
SammyJoe 2019 年 10 月 18 日
I tried this, seems to be an error in the second line; is there a way to make a matrix with this loop?
Bjorn Gustavsson
Bjorn Gustavsson 2019 年 10 月 18 日
Change p2(km :); to: p2(k,:); That should fix that problem.
For future work, read the error message look at what it says, look at the code snippet and try to see if you can spot the error. You most likely got an error-message along the lines of "Undefined function or variable 'km'." You will have to learn to spot that kind of error sooner or later, the sooner you do the better for you.
HTH

サインイン to comment.

サインイン してこの質問に回答します。


Translated by