Hi, I have a matrix
T =
1 0
1 1
and i want to generate this matrix
T =
1 0 0 0
1 1 0 0
0 1 1 0
0 0 1 1
please note that T is not exactly repeating at diagonal. Can anyone help me with this ? thank you

 Akzeptierte Antwort

Andrei Bobrov
Andrei Bobrov am 7 Sep. 2017
Bearbeitet: Andrei Bobrov am 7 Sep. 2017

2 Stimmen

T = [1,0;1,1];
N = 4;
[~,d] = spdiags(T);
out = full(spdiags(ones(N,numel(d)),d,N,N));
or
out = triu(tril(ones(N),sum(T(1,:))-1),1-sum(T(:,1)));

2 Kommentare

More general than my method. Because he didn't give any rules, I was going to just give the very simple and straightforward (but snarky) answer of
T = [...
1 0 0 0
1 1 0 0
0 1 1 0
0 0 1 1]
Stephen23
Stephen23 am 7 Sep. 2017
@Image Analyst: nice. It fits the given explanation perfectly :)

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (2)

Stephen23
Stephen23 am 7 Sep. 2017

3 Stimmen

I suspect you might want something like this:
>> T = [1,0;1,1];
>> N = 4;
>> R = zeros(1,N);
>> C = zeros(1,N);
>> R(1:size(T,1)) = T(:,1);
>> C(1:size(T,2)) = T(1,:);
>> toeplitz(R,C)
ans =
1 0 0 0
1 1 0 0
0 1 1 0
0 0 1 1
>>
but without a clear explanation of the algorithm that generates the output matrix from the input matrix, this is just a guess.

2 Kommentare

Shajeel Iqbal
Shajeel Iqbal am 7 Sep. 2017
Yes that's what i want. thank you
Andrei Bobrov
Andrei Bobrov am 7 Sep. 2017
+1. Very good method!

Melden Sie sich an, um zu kommentieren.

KSSV
KSSV am 7 Sep. 2017

1 Stimme

T = ones(4,1) ;
K = diag(T)+diag(T(1:end-1),-1)

Kategorien

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by