cell array indexing oddity
1 回表示 (過去 30 日間)
古いコメントを表示
i have a large cell array of type cell
when i do this
test{2:2:end,7} i get back cells
when i do this i get back ints that are in the cell
test{1,1}
Its very frustrating, I wanted to access all the rows from 2 to the end skipping one in the midding of col 7
Why is that so hard?
It works for a single instance but cant do it in a vectorized form
6 件のコメント
DGM
2021 年 7 月 29 日
A = num2cell(reshape(1:70,10,[]))
A{2:2:end,7} % output is multiple scalars
vertcat(A{2:2:end,7}) % output is a single column vector
You need to deal with the fact that that expression has multiple outputs.
回答 (1 件)
Image Analyst
2021 年 7 月 29 日
I know you said you tried using cell2mat(), but you must have not used it correctly. Try using cell2mat() like this:
test = num2cell(reshape(1:80,10,[])) % 10 rows by 8 columns
% Take contents of 7th column and even numbered rows.
% 7th column has 10 elements.
out = cell2mat(test(:,7)); % Get 7th column.
out = out(2:2:end) % Every other element to give 5 elements.
whos test
whos out
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Whos についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!