3 views (last 30 days)

The vector structure is like [a b c d e f g h i j]

a=1:10

b=1:10

...

j=1:5

vect=[]

I can use for a =1:10

for b=1:10

...

vect = [vect;a.b...j]

end

end

but it looks not elegant. Is there a better way to generate it?

Walter Roberson
on 19 Jan 2020

a=1:10;

b=1:10;

c=1:3;

d=1:5;

[A, B, C, D] = ndgrid(uint8(a), uint8(b), uint8(c), uint8(d)) ;

v = [A(:), B(:), C(:), D(:)] ;

Sign in to comment.

Image Analyst
on 19 Jan 2020

Try

a = 1 : 10

b = 1 : 10

...

j = 1 : 5

outputVector = [a, b, c, d, e, f, g, h, i, j]

Sign in to comment.

Sign in to answer this question.

Opportunities for recent engineering grads.

Apply Today
## 8 Comments

## Direct link to this comment

https://nl.mathworks.com/matlabcentral/answers/500918-create-a-vector-without-for#comment_787469

⋮## Direct link to this comment

https://nl.mathworks.com/matlabcentral/answers/500918-create-a-vector-without-for#comment_787469

## Direct link to this comment

https://nl.mathworks.com/matlabcentral/answers/500918-create-a-vector-without-for#comment_787471

⋮## Direct link to this comment

https://nl.mathworks.com/matlabcentral/answers/500918-create-a-vector-without-for#comment_787471

## Direct link to this comment

https://nl.mathworks.com/matlabcentral/answers/500918-create-a-vector-without-for#comment_787475

⋮## Direct link to this comment

https://nl.mathworks.com/matlabcentral/answers/500918-create-a-vector-without-for#comment_787475

## Direct link to this comment

https://nl.mathworks.com/matlabcentral/answers/500918-create-a-vector-without-for#comment_787476

⋮## Direct link to this comment

https://nl.mathworks.com/matlabcentral/answers/500918-create-a-vector-without-for#comment_787476

## Direct link to this comment

https://nl.mathworks.com/matlabcentral/answers/500918-create-a-vector-without-for#comment_787478

⋮## Direct link to this comment

https://nl.mathworks.com/matlabcentral/answers/500918-create-a-vector-without-for#comment_787478

## Direct link to this comment

https://nl.mathworks.com/matlabcentral/answers/500918-create-a-vector-without-for#comment_787481

⋮## Direct link to this comment

https://nl.mathworks.com/matlabcentral/answers/500918-create-a-vector-without-for#comment_787481

## Direct link to this comment

https://nl.mathworks.com/matlabcentral/answers/500918-create-a-vector-without-for#comment_787482

⋮## Direct link to this comment

https://nl.mathworks.com/matlabcentral/answers/500918-create-a-vector-without-for#comment_787482

## Direct link to this comment

https://nl.mathworks.com/matlabcentral/answers/500918-create-a-vector-without-for#comment_787523

⋮## Direct link to this comment

https://nl.mathworks.com/matlabcentral/answers/500918-create-a-vector-without-for#comment_787523

Sign in to comment.