Creating m by m matrix in matlab

  • Context: MATLAB 
  • Thread starter Thread starter sugaku
  • Start date Start date
  • Tags Tags
    Matlab Matrix
Click For Summary
SUMMARY

The discussion focuses on generating an m by m matrix in MATLAB using a vector z. The user initially attempts to create the matrix using a loop, which is inefficient for larger values of m. The recommended solution is to utilize the repmat() function, specifically repmat(z, size(z, 2), 1), to achieve this in a single command, providing a more efficient and vectorized approach.

PREREQUISITES
  • Familiarity with MATLAB programming language
  • Understanding of matrix operations in MATLAB
  • Knowledge of vectorized functions in MATLAB
  • Basic understanding of the repmat() function
NEXT STEPS
  • Explore the repmat() function in MATLAB documentation
  • Learn about other vectorized operations in MATLAB for efficiency
  • Investigate memory management techniques in MATLAB for large matrices
  • Study MATLAB's built-in functions for matrix manipulation
USEFUL FOR

MATLAB programmers, data analysts, and anyone looking to optimize matrix generation and manipulation in MATLAB.

sugaku
Messages
16
Reaction score
0
hi all,

i have a vector, z which size is 1 by m.
z = [1 2 3 4 5 6 7 8]

then i want to make a matrix with m by m
Z= [z; z; z; z; z; z; z; z]

if m become bigger i couldn't do it like mentioned above. how could i generate the matrix by a single command?

thank you in advance.
 
Physics news on Phys.org
A kind of brute fortish method would be
A=zeros(m)
for r=1:m
A(r,:)=z;
end

I don't know if there's a vectorized way to do it but there probably is
 
See the repmat() function. For your purpose its repmat(z, size(z)(2), 1)
 

Similar threads

  • · Replies 3 ·
Replies
3
Views
4K
  • · Replies 2 ·
Replies
2
Views
4K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 6 ·
Replies
6
Views
4K
  • · Replies 32 ·
2
Replies
32
Views
4K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 2 ·
Replies
2
Views
12K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K