How Can i create 3*3 matrix from 1*3 matrix?
7 views (last 30 days)
Show older comments
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?
0 Comments
Accepted Answer
Azzi Abdelmalek
on 23 Jul 2016
[b;zeros(2,numel(b))]
2 Comments
Azzi Abdelmalek
on 23 Jul 2016
b=[1 2 3]
c=zeros(6)
c(1,1:3)=b
You need to read the documentation: http://www.mathworks.com/help/matlab/learn_matlab/matrices-and-arrays.html
More Answers (3)
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
Meribeni
on 30 Dec 2022
How can I create 3×3 and 4×4 matrix using matlab
1 Comment
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:
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
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?
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.
See Also
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!