I'm having a problem getting cell data into usable forms

For my latest HW I've been given a lot of data in the form of several 175x1 cells, each containing a single column of Nx1 doubles where N is from ~20 to 70. I'm required to use this data to perform histograms of various types, determine directional vectors based upon these points, and similar functions, but can't figure out good ways to access the data without going row-by-row hundreds of times. The cell2mat function just gives me a 5413x1 matrix, making it hard to do much productive with the data. Is there some easy step I'm missing here? Thanks for any help.

 Accepted Answer

Without your actual data it’s difficult to give an exact Answer. However, if your cell array resembles this one, see if taking the transpose of your cell array solves your problem.
Example:
c = { randi(9,10,1); randi(9,10,1); randi(9,10,1)};
d = cell2mat(c');

4 Comments

Thanks for the answer, Star Strider. Unfortunately the different elements of the cell are not uniform so I get a "Dimensions of matrices being concatenated are not consistent" error when I try to use the transpose. I'd try to post the data, but the size is immense and wouldn't begin to fit in the character limit.
I misread your Question. I thought they were all (175x1). Reading it again, I understand the problem.
You’re probably going to have to use a loop:
c = { randi(9,20,1) randi(9,50,1) randi(9,70,1)};
for k1 = 1:size(c,2)
figure(k1)
histogram(c{k1})
end
Make the appropriate changes to be compatible with your data.
That wasn't exactly what was needed, but it got me going down the right path. I had to set up a for loop to individually combine each of the cell arrays using vertcat. There was also another step I was missing: I had to use diff to get the intervals between the time events, which I was able to do individually within the for loop before I vertcated them. Q3 got harder as I then had to make 8 subplot histograms by referencing each array to a separate "key" matrix. Fun times. Thanks, Star Strider, you got me pointed in the right direction!

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!