Extracting Vector from Cell Array Row or Column
31 ビュー (過去 30 日間)
古いコメントを表示
When trying to extract a row (or column) vector from a Cell Array it appears that the type of the cells in the Cell Array is determining whether or not a row vector can be extracted. Here's an example:
>> timeC = [timeB{1:end}];
>> class(timeC)
ans =
'char'
>>
As shown, the result does not produce a vector but instead a character array of all the cell array cells. What is the best way to extract a row or column from a cell array into a row or column vector. Also enclosed is a .mat file with the example cell array for converting to a row or column vector.

3 件のコメント
回答 (1 件)
Jan
2017 年 7 月 24 日
編集済み: Jan
2017 年 7 月 24 日
When trying to extract a row (or column) vector from a Cell Array
Was does "extracting" mean? Your code:
[timeB{1:end}]
concatenates the contents of the cell elements, which are obviously char vectros in your case. But what is the wanted result? Perhaps you mean:
datenum(timeB)
See this:
C = {'a', 'b'; 'c', 'd'}
C_row1 = C(1, :)
C_col1 = C(:, 2)
[EDITED] After your comment:
This is a misunderstanding of the nature of cells. The shown cell contains char vectors. So you cannot obtain them "as a vector", because there are no vectors of vectors in Matlab. If you want to store a bunch of vectors, use either a matrix or a cell. In you case, timeB is a cell vector already and there is no more vector like container for these kind of data - except you want to concatenate the cell elements to a single string.
This is different, if the cell contains numbers:
C = {1,2,3}
v = [C{:}]
Now you get [1,2,3] as a vector. Clear?
it appears that I can just treat this timeB cell array as an array
for some reason.
Yes of course this cell array is an array also - of type cell. You can extract sub-cells by round parenthesis
a = timeB(2)
class(a)
or elements with curly braces
b = timeB{2}
class(b)
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Matrix Indexing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!