필터 지우기
필터 지우기

creation of toeplitz matrix

조회 수: 6 (최근 30일)
g
g 2021년 12월 15일
댓글: Star Strider 2021년 12월 15일
Good morinig,
i have a cell matrix ( 6 x 1 ) where inside each cell i have a vector of two values. I would like to get a toeplitz matrix and I tried to use the command toeplitz(c,r) but I got the following error 'Inputs must be numeric'. In fact inside each cell I don't have a single value but a vector of two values.
What can i do? thanks

답변 (1개)

Star Strider
Star Strider 2021년 12월 15일
It would help to see the code, since I have no idea what ‘r’ is.
That aside, try something like this —
cell_matrix = {rand(1,2); rand(1,2); rand(1,2)}
cell_matrix = 3×1 cell array
{[0.8842 0.4232]} {[0.5807 0.8143]} {[0.9432 0.7645]}
r = rand(1,2)
r = 1×2
0.7594 0.9229
tm = toeplitz([cell_matrix{:}], r)
Warning: First element of input column does not match first element of input row.
Column wins diagonal conflict.
tm = 6×2
0.8842 0.9229 0.4232 0.8842 0.5807 0.4232 0.8143 0.5807 0.9432 0.8143 0.7645 0.9432
This indexing convention extracts the data in the comma-separated list of the cell array and concatenates it, creating a numeric vector. I have no idea if that numeric vector is the desired one. Another option is the cell2mat function.
See Access Data in Cell Array for more details.
.
  댓글 수: 2
g
g 2021년 12월 15일
편집: g 2021년 12월 15일
what I mean is that I have:
cell_matrix =
{[0.9503 0.5174]}
{[0.2850 0.6280]}
{[0.4221 0.3325]}
And from this array I want to get the toeplitz matrix:
toeplitz_matrix=
[0.9503 0.5174] [0 0 ][0 0 ]
[0.2850 0.6280] [0.9503 0.5174] [0 0 ]
[0.4221 0.3325][0.2850 0.6280] [0.9503 0.5174]
To do this I tried using
toeplitz(c,r)
where c corresponds to the first column and r to the first row. But I got the following error 'Inputs must be numeric'.
Star Strider
Star Strider 2021년 12월 15일
It appears to be a ‘cell-of-cells’, so —
cell_matrix = { {[0.9503 0.5174]}
{[0.2850 0.6280]}
{[0.4221 0.3325]} }
cell_matrix = 3×1 cell array
{1×1 cell} {1×1 cell} {1×1 cell}
M = cellfun(@cell2mat, cell_matrix, 'Unif',0)
M = 3×1 cell array
{[0.9503 0.5174]} {[0.2850 0.6280]} {[0.4221 0.3325]}
M = cell2mat(M)
M = 3×2
0.9503 0.5174 0.2850 0.6280 0.4221 0.3325
c = M(:,1)
c = 3×1
0.9503 0.2850 0.4221
r = M(1,:)
r = 1×2
0.9503 0.5174
Tm = toeplitz(c, r)
Tm = 3×2
0.9503 0.5174 0.2850 0.9503 0.4221 0.2850
That would appear to be the desired result.
.

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

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by