Extract Data from Cell Array with specified key word in other cell
1 view (last 30 days)
Show older comments
I have this cell array (first 10 columns):
'year' 2013 'day' 96 'minute' 50 'sec' 35 [] NaN
'year' 2013 'day' 96 'hour' 11 'minute' 24 'sec' 31
'year' 2013 'day' 96 'hour' 14 'minute' 52 'sec' 34
'year' 2013 'day' 96 'minute' 35 'sec' 5 [] NaN
and want to get this matrix:
2013 96 0 50 35
2013 96 11 24 31
2013 96 14 52 34
2013 96 0 35 5
I already have produced logical matrixes with
distribution(:, :, 1) = strcmp(cell_array, 'year');
distribution(:, :, 2) = strcmp(cell_array, 'day');
... etc
looking like this:
distribution(:, :, 1) =
[1 0 0 0 0 0 0 0 0 0;
1 0 0 0 0 0 0 0 0 0;
1 0 0 0 0 0 0 0 0 0;
etc
and then with:
distribution = circshift(distribution, [0 1]);
I ll get the desired Logicals for each key word but cannot manage to get a new matrix like shown above. Whenever the loop (cycling through each col) encounters a "0" because there is no entry (like in first row for "hour") the loop is aborted because of dimension mismatch.
In my mind I thought (not real code):
cell_array * distribution(:,:,1) = [2013, 2013, 2013 ... ]
but this obviously doesn't work.
Any help appreciated for a solution without a for loop ;)
Fl0
3 Comments
Walter Roberson
on 14 Nov 2016
It is not clear to me how those could all be in columns if you have a different number of entries on each line. Are there padding entries on the shorter lines, or is each row a cell array?
More Answers (0)
See Also
Categories
Find more on Matrices and Arrays in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!