creation of toeplitz matrix

5 vues (au cours des 30 derniers jours)
g
g le 15 Déc 2021
Commenté : Star Strider le 15 Déc 2021
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

Réponses (1)

Star Strider
Star Strider le 15 Déc 2021
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 commentaires
g
g le 15 Déc 2021
Modifié(e) : g le 15 Déc 2021
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 le 15 Déc 2021
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.
.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange

Produits


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by