Extract Data from Cell Array with specified key word in other cell
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
Walter Roberson
2016-11-14
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?
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrices and Arrays 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!