Converting matirx into vektor inside a cell array

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

 採用された回答

Alex Mcaulley
Alex Mcaulley 2020 年 2 月 20 日

0 投票

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

その他の回答 (1 件)

the cyclist
the cyclist 2020 年 2 月 20 日

1 投票

ev1 = cellfun(@(x)x(:,1),V,'UniformOutput',false);
ev2 = cellfun(@(x)x(:,2),V,'UniformOutput',false);

6 件のコメント

Antonio Sarusic
Antonio Sarusic 2020 年 2 月 20 日
This somehow doesn't compute...
the cyclist
the cyclist 2020 年 2 月 20 日
That's odd. It worked for a test array that mimicked what you described.
If you want to upload your cell array V, I could poke around. But at least you have a solution.
Antonio Sarusic
Antonio Sarusic 2020 年 2 月 20 日
The cell array V is to big to upload.
But here ist the matrix I started with and the code I hade until this point:
[m,n]=size(Bild);
[Gx,Gy] = imgradientxy(Bild);
[Gxx,Gxy] = imgradientxy(Gx);
[Gyx,Gyy] = imgradientxy(Gy);
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
for i=1:n
for j=1:m
ev1 = cellfun(@(x)x(:,1),V,'UniformOutput',false);
ev2 = cellfun(@(x)x(:,2),V,'UniformOutput',false);
end
end
the cyclist
the cyclist 2020 年 2 月 20 日
Sorry, I don't have the Image Processing Toolbox, so I think we are at an impasse. :-/
the cyclist
the cyclist 2020 年 2 月 20 日
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 2020 年 2 月 20 日
Ok. I'll give it a try.
Thank you!

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeDeep Learning Toolbox についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by