How can I create a new matrix by using existing values in a column?
15 views (last 30 days)
Show older comments
I've a column inluding the values of
>> B=[0.100;0.250;0.200;0.120;0.080;0.060;0.055;0.040;0.020]
B =
0.1000
0.2500
0.2000
0.1200
0.0800
0.0600
0.0550
0.0400
0.0200
But I want to make it as
0.100 0 0 0 0 0 0 0 0
0.250 0.100 0 0 0 0 0 0 0
0.200 0.250 0.100 0 0 0 0 0 0
0.120 0.200 0.250 0.1 0 0 0 0 0
0.080 0.120 0.200 0.250 0.1 0 0 0 0
0.060 0.080 0.120 0.200 0.25 0.1 0 0 0
0.055 0.060 0.080 0.120 0.2 0.25 0.1 0 0
0.040 0.055 0.060 0.080 0.12 0.2 0.25 0.1 0
0.020 0.040 0.055 0.060 0.08 0.12 0.2 0.25 0.1
How can I do it?
0 Comments
Accepted Answer
Stephen23
on 13 Dec 2018
Edited: Stephen23
on 13 Dec 2018
>> B = [0.100;0.250;0.200;0.120;0.080;0.060;0.055;0.040;0.020];
>> C = zeros(size(B));
>> C(1) = B(1);
>> M = toeplitz(B,C)
M =
0.100 0 0 0 0 0 0 0 0
0.250 0.100 0 0 0 0 0 0 0
0.200 0.250 0.100 0 0 0 0 0 0
0.120 0.200 0.250 0.100 0 0 0 0 0
0.080 0.120 0.200 0.250 0.100 0 0 0 0
0.060 0.080 0.120 0.200 0.250 0.100 0 0 0
0.055 0.060 0.080 0.120 0.200 0.250 0.100 0 0
0.040 0.055 0.060 0.080 0.120 0.200 0.250 0.100 0
0.020 0.040 0.055 0.060 0.080 0.120 0.200 0.250 0.100
0 Comments
More Answers (2)
TADA
on 12 Dec 2018
Edited: TADA
on 12 Dec 2018
B=[0.100;0.250;0.200;0.120;0.080;0.060;0.055;0.040;0.020];
n = length(B);
% prepare indices
idx = 0:(length(B)-1);
% splicing and padding
func = @(i) padarray(B(1:n-i), i, 'pre');
% execute padding and splicing element-wise
c = arrayfun(func, idx, 'UniformOutput', false);
result = cell2mat(c)
result =
0.1000 0 0 0 0 0 0 0 0
0.2500 0.1000 0 0 0 0 0 0 0
0.2000 0.2500 0.1000 0 0 0 0 0 0
0.1200 0.2000 0.2500 0.1000 0 0 0 0 0
0.0800 0.1200 0.2000 0.2500 0.1000 0 0 0 0
0.0600 0.0800 0.1200 0.2000 0.2500 0.1000 0 0 0
0.0550 0.0600 0.0800 0.1200 0.2000 0.2500 0.1000 0 0
0.0400 0.0550 0.0600 0.0800 0.1200 0.2000 0.2500 0.1000 0
0.0200 0.0400 0.0550 0.0600 0.0800 0.1200 0.2000 0.2500 0.1000
Mark Sherstan
on 12 Dec 2018
Try this:
B = [0.100;0.250;0.200;0.120;0.080;0.060;0.055;0.040;0.020]
A = zeros(1,length(B));
for ii = 1:length(B)
A = circshift(A,1);
A(1) = B(ii)
end
0 Comments
See Also
Categories
Find more on Data Distribution Plots 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!