Find the values in the cell arrays that correspond to some specific indices
1 次查看(过去 30 天)
显示 更早的评论
I have a cell array of size 99x90 (named A). Each cell includes either a scalar, either an array, either a NaN. I have created a matrix of size 99x90 (named B), with each cell including the index of the value that I would like to isolate from the corresponding cell in A. If the cell in A includes a scalar then the corresponding cell in B includes the scalar 1, if the cell in A includes an array then the corresponding cell in B includes a scalar no larger than the length of the array and if the cell in A includes a NaN then the corresponding cell in B includes a NaN. I would like to create a matrix of size 99x90 (named C) with the values that correspond to the indices in matrix B. Any idea how to do this?
SIMPLE EXAMPLE:
A = { [10 30 2] [2] [NaN] ; [4] [NaN] [NaN] ; [30 2] [10 2] [3] }
B = [ 2 1 NaN ; 1 NaN NaN ; 2 1 1 ]
C = [ 30 2 NaN ; 4 NaN NaN ; 2 10 3 ]
0 个评论
采纳的回答
Jan
2022-4-20
If I understand correctly, A and B are the existing input and you want to create C. Then:
A = { [10 30 2] [2] [NaN] ; [4] [NaN] [NaN] ; [30 2] [10 2] [3] };
B = [ 2 1 NaN ; 1 NaN NaN ; 2 1 1 ];
C = NaN(size(A));
for k = 1:numel(A)
if ~isnan(B(k))
C(k) = A{k}(B(k));
end
end
C
更多回答(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!