Single Line Command for Row Vector

8 Ansichten (letzte 30 Tage)
Basem Sharafeldin
Basem Sharafeldin am 14 Okt. 2015
Beantwortet: NURUL am 10 Apr. 2023
HELP I need a single line command to create a row vector, variable named v11 that assigns the values 1/2,1/3,1/4,1/5...1/1000 in that order. It has a total of 999 terms. Please I have been trying forever but cant figure it out. It cannot be greater than 1 line. It should look like [.5,.33,.25,...,.001]. I tried using the colon command and linspace and other ways.

Akzeptierte Antwort

John D'Errico
John D'Errico am 14 Okt. 2015
Bearbeitet: John D'Errico am 14 Okt. 2015
Can you generate the numbers 2 through 1000? Can you do that in one expression? (Hint - what does the colon (:) operator do?)
Can you use element-wise division to achieve what you want? (Hint - use the ./ operator.) For example, what is 1 divided by each of the elements, 2 through 1000?
The point is, try what I describe above. Learn to use MATLAB, and how it works on vectors and arrays. You learn by trying things out. By seeing what happens. Sometimes, it will help to try something that does part of what you need, then try taking the next step.
  1 Kommentar
Basem Sharafeldin
Basem Sharafeldin am 15 Okt. 2015
Hey thanks a lot! I played a little with it and composed v11=1/2:1000.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

NURUL
NURUL am 10 Apr. 2023
b = 2 3 4 5 6 7 8 7 6 5 4 3 2
how to create row vector using single command

Community Treasure Hunt

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

Start Hunting!

Translated by