Need Help Indexing. I have a 1x12 cell array with each cell containing a 120x2 double. I need to use a for loop to index all the values in every of row in the second column of the 120x2 double and store them in their own 1x12 matrix.
3 次查看(过去 30 天)
显示 更早的评论
Cool = Matrix(:,2);
[row,col] = size(Cool);
N = 1;
M = 1;
for N = 1:1:col
for M = 1:1:row
Cool_Temp{M} = Cool{M}(:,2);
end
end
0 个评论
回答(1 个)
Peng Li
2020-4-3
Do you necessarily do with a for loop? If not, you don't need one.
% an example
tst = cell([1, 12]);
tst(:) = {randn(120, 2)};
% extract the second column of each cell element and store them in another cell
res = cellfun(@(x) x(:, 2), tst, 'UniformOutput', 0);
>> res
res =
1×12 cell array
Columns 1 through 6
{120×1 double} {120×1 double} {120×1 double} {120×1 double} {120×1 double} {120×1 double}
Columns 7 through 12
{120×1 double} {120×1 double} {120×1 double} {120×1 double} {120×1 double} {120×1 double}
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!