Unequal array lengths of vectors

I have two vectors, x = 5,6,4,8,9 and y = 3, 2, 4
How would I create a 5x5 matrix or a 7x8 matrix using X and Y?

6 Comments

Could you post the 5-by-2 or the 5-by-5 matrix that you want to create using those two vectors? I think I can guess what you want the 5-by-2 matrix to be, but I'm not sure what you want the 5-by-5 matrix to be.
Is there a way to combine these two arrays to create a 5x5 matrix or like a 7 by 8 matrix?
Mathematically there are an infinite number of ways to combine those two vectors to create a 5 x 5 or 7 x 8 matrix. It would help a lot of you could give an example of the 5 x 5 or 7 x 8 matrix you would want output.
Jake, here's a matrix that will make a 5x5 matrix:
m = [...
x(1), x(2), x(3), x(4), x(5);...
y(1), y(2), y(3), y(1), y(2);...
x(1), x(2), x(3), x(4), x(5);...
y(2), y(3), y(1), y(1), y(2);...
x(1), x(2), x(3), x(4), x(5)]
How about that? It does everything you've told us so far (which isn't much). Will that work for you? If not, then give us the actual output you want.
There are many ways to create a 5-by-5 matrix using x and y. Here are four examples.
x = [5, 6, 4, 8, 9];
y = [3, 2, 4];
v = [x, y];
% Ignore the vectors entirely
A = eye(5);
% Only use one of the arrays
B = repmat(x, 5, 1);
% Random selection of elements from the combined vector
C = v(randi(length(v), [5 5]));
% Keep replicating the elements in order until you have enough
n = ceil(25/length(v));
v2 = repmat(v, 1, n);
D = reshape(v2(1:25), 5, 5);
If you describe in more detail what you want the result to look like (A, B, C, D, or something else entirely -- and in that last case, please be specific) we can suggest ways to achieve that result.
The matrix I want to output for a 7 by 8, but it could be any matrix that uses those two vectors to create the matrix:
5 6 7 8 9 3 2 4
5 6 7 8 9 3 2 4
5 6 7 8 9 3 2 4
5 6 7 8 9 3 2 4
5 6 7 8 9 3 2 4
5 6 7 8 9 3 2 4
5 6 7 8 9 3 2 4

Sign in to comment.

More Answers (0)

Categories

Tags

Asked:

on 18 Jan 2018

Edited:

on 19 Jan 2018

Community Treasure Hunt

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

Start Hunting!