Generate matrix from non empty cells from another cell array

I have a cell matrix like this
I need to generate matrix for the non empty cell in these format and arrange row by row ( form above to below)
A = [ 16 3
21 3
16 4
22 4
4 5
9 5
16 5
22 5
. . ] so on.
How can we do that?

 採用された回答

madhan ravi
madhan ravi 2020 年 7 月 10 日

0 投票

c = cell_array.';
ix = cellfun('isempty',c);
w = cellfun(@flip,c(~ix),'un',0);
Wanted = cat(1, w{:})

4 件のコメント

Islam Hassan
Islam Hassan 2020 年 7 月 10 日
Thanks for the reply.
I upload the code I am working on, the function I want to need to generate matrix for the non empty cell in these format and arrange row by row ( form above to below) called " Location ". you can find it in the for loop.
And AA is the wanted matrix like I showed in the first comment.
clc
clear all
baseFileName = 'I-3.png'; % donot foregt to chage the video name
% baseFileName = 'i-4.png';
fullFileName = imread (baseFileName);
Z = rgb2gray(fullFileName);
imshow (Z)
[counts,x] = imhist(Z);
% %stem(x,counts)
T = otsuthresh(counts);
BW = imbinarize(Z,T);
imshow (BW)
BW = edge(BW);
imshow (BW)
[row,col]=find(BW==1);
imshow(BW)
hold on
plot(col,row,'xc')
hold off
Intensity_at_location = BW(5,3);
[v,q] = size (BW);
for i = 1 : v-1
for j = 2 : q-1
% if BW (i,j)==1
Int = BW (i,j);
Intleft = BW (i,j-1);
Intright = BW (i, j+1);
if isequal (Int,Intleft,Intright)
location{i,j} = [];
elseif Int == 0 && Intleft == 0 && Intright == 1
location{i,j} = [];
elseif Int == 0 && Intright == 0 && Intleft == 1
location{i,j} = [];
else
location{i,j} = [i j];
end
% else
end
end
% end
% %
% A = cell2mat(location);
% imshow(A);
% c = cell_array.';
ix = cellfun('isempty',location);
w = cellfun(@flip,location(~ix),'un',0);
AA = cat(1, w{:})
Thanks in advance
Islam Hassan
Islam Hassan 2020 年 7 月 10 日
I used these lines
M= location(~cellfun('isempty',location));
AA = cell2mat(M);
it gives me same results, but Ineed to scan row by row, not column by column.
Thanks
madhan ravi
madhan ravi 2020 年 7 月 10 日
Then don’t transpose ;).
Islam Hassan
Islam Hassan 2020 年 7 月 10 日
Thanks a lot

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

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by