Assign a Sub Array to Array Knowing the Number of Dimensions at Run Time
조회 수: 5 (최근 30일)
이전 댓글 표시
Assume we have tA and tB with the same number of dimesions. We also have all(size(tB) <= size(tA)) == true.
The task is to embed tB in tA. Something like: tA(1:size(tB, 1), 1:size(tB, 2), ..., 1:size(tB, n)) = tB. Yet since we know the number of dimensions only at runtime, it can't be written explicitly like that.
The question, is there an efficient way to do so without eval or explicitly computer the cartesian product and use sub2ind()?
댓글 수: 0
채택된 답변
Royi Avital
2022년 2월 10일
편집: Royi Avital
2022년 2월 11일
추가 답변 (1개)
Rik
2022년 2월 10일
There is probably a better way, but you can fill a cell array with the index vectors (simple loop with ndims), and then use this:
tA(inds{:}) = tB;
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!