Click here to Skip to main content
15,879,348 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi I want to build a m*n matrix in Matlab but i don't know how? I know I can build a vector with many ways but about matrices I couldn't find any way!

For example if I want to build a matrix 100*100 like this:
[1 2 3 .......100
1 2 3 .......100
1 2 3 .......100
.
.
.
1 2 3 .......100]

How can I build it?

I've found a way but don't know is it the best or not?

a=1:100;
b=a([1 1 1 1....(100times)], [1:end]);
Posted
Updated 5-Nov-14 23:10pm
v3

1 solution

Try this:
VB
% create an all zeros 100x100 matrix
m=100;
n=100;
matrix = zeros(m, n);
% create a column vector of 1x100
v = 1:n;
v
% create a 100x100 matrix
for r=1:m
   matrix(r, :) = v;
end
matrix
 
Share this answer
 
v2
Comments
Albert Holguin 6-Nov-14 10:47am    
+5... it's pretty trivial. For the OP, don't forget you can experiment with things right no the command prompt. If you're not sure what a call does, type in on the prompt and don't put a semicolon at the end and it will output to the prompt.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900