How can I concatenate only the contents of the cells in a cell array whose length is more than a specific number?

I have a cell array (r) as given below.
r{1,1} = [1 2]
r{1,2} = 1x15 double which is like [3 4 ......17]
r{1,3} = [18 19]
r{1,4} = 1x16 double which is [20 21 ......35]
r{1,5} = 1x5 double [36 37 38 39 40]
it goes on till
r{31,1} = [107 108 109];
How can I concatenate only the contents of the cells whose length is more than 4? My output should be a single array which looks like [3 4 5..........17 20 21 ....35 36 37 38 39 40.....] Only the cells which have more than 4 elements should get concatenated.
Thanks in advance

 Accepted Answer

Quicklearner - iterate over each element in the cell array and check its length. If greater than four, then concatenate it with the other like data arrays. Something like
data = [];
for k=1:size(r,2)
temp = r{1,k};
if length(temp)>4
data = [data temp];
end
end
Try the above and see what happens!

1 Comment

Hello, Thanks a lot for your answer, I had an error with my account and was not able to login. Apologise for the late acknowledgement. Cheers. Quicklearner.

Sign in to comment.

Categories

Community Treasure Hunt

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

Start Hunting!