Info

This question is closed. Reopen it to edit or answer.

How to code like this (please read)

1 view (last 30 days)
swynt
swynt on 3 Sep 2014
Closed: MATLAB Answer Bot on 20 Aug 2021
Dear all,
sorry for the confusing title, because I lack the experience in MATLAB. so, I need a script that can produce this kind of matrix. e.g. a = { a1 a2 a3; a4 a5 a6; a7 a8 a9} so, a1 = a5 = a9 = 1 >> this will be 'eye(a)' then suppossed a2 = 6, a3 = -4, a6 = 0,5; then a4 = a2, a7 = a3, a8 = a6. any hints for coding this script? thanks in advance.
CS

Answers (1)

Star Strider
Star Strider on 3 Sep 2014
You can do this by using the toeplitz function twice:
A = toeplitz([1 6 -4]);
A(2:3,2:3) = toeplitz([1 0.5]);
produces:
A =
1 6 -4
6 1 0.5
-4 0.5 1

Tags

Community Treasure Hunt

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

Start Hunting!