1

I have a vector

rand(1,10)

and I want to access some of the elements immediately after creating the vector. For example, I can do this by the following code:

A=rand(1,10)
A(2:5)

Using these two lines, I can access the 2nd to 5th elements. However, I must create a variable "A" to do this. Then how can I avoid creating the variable?

I have tried the following codes:

rand(1,10)(2:5)
(rand(1,10))(2:5)

But they both do not work.

FrankHan
  • 41
  • 1
  • 5
  • In this specific example, you would create `rand(1,4)`. If your actual requirements are different, it would be helpful to give a more realistic example showing how creating an array and then accessing a portion of that array would be advantageous. If you need the full array, what is the disadvantage of assigning it to a variable? If not, then why do you create the full array to begin with? There *are* cases in which this would be useful, but we can't really help without more specifics. – beaker Apr 12 '19 at 21:01

0 Answers0