How can I create a new matrix by using existing values in a column?
Afficher commentaires plus anciens
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?
Réponse acceptée
Plus de réponses (2)
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
1 commentaire
Onur Güven
le 13 Déc 2018
Modifié(e) : Onur Güven
le 13 Déc 2018
Mark Sherstan
le 12 Déc 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
Catégories
En savoir plus sur Data Distribution Plots dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!