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?

 Risposta accettata

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

4 Commenti

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
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
Then don’t transpose ;).

Accedi per commentare.

Più risposte (0)

Categorie

Community Treasure Hunt

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

Start Hunting!

Translated by