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

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

More Answers (3)

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

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.

How can I create 3×3 and 4×4 matrix using matlab

1 Comment

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.

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

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

Asked:

on 23 Jul 2016

Edited:

DGM
on 17 Jul 2023

Community Treasure Hunt

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

Start Hunting!