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!