Converting matirx into vektor inside a cell array

1 vue (au cours des 30 derniers jours)
Antonio Sarusic
Antonio Sarusic le 20 Fév 2020
Commenté : Antonio Sarusic le 20 Fév 2020
Hello,
I have a cell array V (1024x1280 cells).
In every cell of this cell array I saved a 2x2 matrix.
Now i want to split this matrix into two column vectors and save these vectors in two cell arrays ev1 and ev2.
And all this for the entire cell array V.
I had the following idea:
for i=1:n
for j=1:m
[ev1{j,i}] = V{j,i}(1,1);
[ev2{j,i}] = V{j,i}(1,2);
end
end
But with this I only get single values.
Thanks,
Antonio

Réponse acceptée

Alex Mcaulley
Alex Mcaulley le 20 Fév 2020
Try with this:
for i=1:n
for j=1:m
ev1{j,i} = V{j,i}(:,1);
ev2{j,i} = V{j,i}(:,2);
end
end

Plus de réponses (1)

the cyclist
the cyclist le 20 Fév 2020
ev1 = cellfun(@(x)x(:,1),V,'UniformOutput',false);
ev2 = cellfun(@(x)x(:,2),V,'UniformOutput',false);
  6 commentaires
the cyclist
the cyclist le 20 Fév 2020
I will say this, though. It looks like you could use 4-dimensional arrays instead of cell arrays.
V = zeros(m,n,2,2);
D = zeros(m,n,2,2);
for i=1:n
for j=1:m
HesseM = [Gxx(j,i) Gxy(j,i); Gyx(j,i) Gyy(j,i)];
[V(j,i,:,:),D(j,i,:,:)] = eig(HesseM);
end
end
Then the next operation is ...
ev1 = V(:,:,:,1);
ev2 = V(:,:,:,2);
and other downstream operations might also be easier, and probably execute faster.
Antonio Sarusic
Antonio Sarusic le 20 Fév 2020
Ok. I'll give it a try.
Thank you!

Connectez-vous pour commenter.

Catégories

En savoir plus sur Structures dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by