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

 채택된 답변

Andrei Bobrov
Andrei Bobrov 2017년 9월 7일
편집: Andrei Bobrov 2017년 9월 7일

2 개 추천

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

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 2017년 9월 7일
@Image Analyst: nice. It fits the given explanation perfectly :)

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

Stephen23
Stephen23 2017년 9월 7일

3 개 추천

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

Shajeel Iqbal
Shajeel Iqbal 2017년 9월 7일
Yes that's what i want. thank you
Andrei Bobrov
Andrei Bobrov 2017년 9월 7일
+1. Very good method!

댓글을 달려면 로그인하십시오.

KSSV
KSSV 2017년 9월 7일

1 개 추천

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

카테고리

도움말 센터File Exchange에서 Operating on Diagonal Matrices에 대해 자세히 알아보기

제품

질문:

2017년 9월 7일

댓글:

2017년 9월 7일

Community Treasure Hunt

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

Start Hunting!

Translated by