Clear Filters
Clear Filters

Concatenating elements of vectros without loops

1 view (last 30 days)
Hello, I want to do the following without need for loops.
x = [1 2 3];
y = [5 10];
c = 1;
for i = 1:3
for j = 1:2
z(c,:) = [x(i), y(j)];
c = c+1;
end
end
z
Is it possible?

Accepted Answer

Voss
Voss on 19 Apr 2022
x = [1 2 3];
y = [5 10];
[xx,yy] = meshgrid(x,y);
z = [xx(:) yy(:)]
z = 6×2
1 5 1 10 2 5 2 10 3 5 3 10

More Answers (0)

Categories

Find more on Creating and Concatenating Matrices in Help Center and File Exchange

Products


Release

R2020a

Community Treasure Hunt

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

Start Hunting!