Need help with steps and code to complete this.

1 Ansicht (letzte 30 Tage)
Debra Henke
Debra Henke am 9 Apr. 2019
Bearbeitet: Jan am 9 Apr. 2019
1. Write a short program in matlab that does the following:
(i) Creates a vector that is 100 elements long, containing the numbers 1-20 repeated five times each, occurring in random order within the vector.
(ii) Have the program do this five times, creating five separate vectors, and save them all to a .mat file called "outputVectors.mat" (or similar).
x=(1:100)
I am not sure how to make it repeat in 20s
I tried:
x=(1:20*5)
but it did not work
  3 Kommentare
Debra Henke
Debra Henke am 9 Apr. 2019
x=(1:100)
I am not sure how to make it repeat in 20s
I tried: x=(1:20*5)
but it did not work
Jan
Jan am 9 Apr. 2019
Whenever you post in the forum, that something does not work, be sure to attach eitehr the complete error message or explain the difference between your expectation and the result. Of course 1:20*5 does work. But you want something else.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Jan
Jan am 9 Apr. 2019
Bearbeitet: Jan am 9 Apr. 2019
Please read the "Getting Started" chapters of the documentation and search in the net for "Matlab onramp" to get a short instruction. The forum is not te best location to learn the basics.
Example:
a = [1,2,3]
b = [a, a]
See also the command
doc repmat
and
doc repelem
Finally you want a random order. Start with reading
doc rand
At the bottom you find a "See also" line, which contains similar commands. One of them helps you to shuffle the elements: You want a random permutation.

Kategorien

Mehr zu Entering Commands finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by