How Can i create 3*3 matrix from 1*3 matrix?

7 views (last 30 days)
i have b=[1 2 3] and i want b = [1 2 3;0 0 0;0 0 0] how can i add other elments as zeros to make it 3*3 matrix?

Accepted Answer

Azzi Abdelmalek
Azzi Abdelmalek on 23 Jul 2016
[b;zeros(2,numel(b))]

More Answers (3)

Image Analyst
Image Analyst on 23 Jul 2016
Try this. Use the shortcut trick of setting the bottom right element:
b=[1 2 3] % Original data.
% Make b a 3x3 array:
b(3, 3) = 0
% Or, make b a 6x6 array:
b(6, 6) = 0
  1 Comment
Ravi Patel
Ravi Patel on 23 Jul 2016
how can i add column with zeros ? And i want to make 6*6 matrix with original data of 1*3 matrix. is there any column operation?

Sign in to comment.


Meribeni
Meribeni on 30 Dec 2022
How can I create 3×3 and 4×4 matrix using matlab
  1 Comment
Image Analyst
Image Analyst on 30 Dec 2022
There are lots of ways depending on what you want the values to be. Here are just a few
m = ones(3, 3)
m = magic(3)
m = zeros(3, 3)
m = rand(3, 3)
m = randi(9, 3, 3)
Replace 3 by 4 to make them 4x4 matrices.
To learn other fundamental concepts, invest 2 hours of your time here:

Sign in to comment.


Adinda Maharani
Adinda Maharani on 17 Jul 2023
halo, can someone help me? I have matrix b = 1x1980 --- b = [1, 2, 3, ......,1980] and I want matrix 392x262x1980 ---- b = [1, 2, 3, ......,1980; 1, 2, 3, ......,1980; 1, 2, 3, ......,1980]
  1 Comment
DGM
DGM on 17 Jul 2023
Edited: DGM on 17 Jul 2023
You have a 1x1980 vector, and you want a 392x262x1980 array, but then you suggest that it still has 1980 columns. Which is it?
You can use repmat() and permute(), depending on what you want.
bb = repmat(permute(b,[1 3 2]),[392 262]);
That said, if you're trying to create a 392x262x1980 replicated array, then be aware that the resulting array will occupy 1.6GB of memory. Considering that you'll end up generating other arrays of the same size, it's worth asking whether this one is even necessary. Chances are that you can do whatever you're trying to do without generating a giant replicated array at all.

Sign in to comment.

Categories

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

Community Treasure Hunt

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

Start Hunting!