Index a v dimensional matrix from a matrix with v columns and n rows
1 回表示 (過去 30 日間)
古いコメントを表示
Hello all,
I a have u row and n column matrix, say p, in which I want to store some data. I also have a matrix ind which has per each row the indices that I need in order to write to.
For example let me se the dimension to n=2 and supposing I want to write to position ind(1,:) of P I have:
ind = [1,2;2,6];
p(sub2ind([size(p,1),size(p,2)],ind(1,1),ind(1,1))) = datum; % Ican easly loop to handle more data
While this works I am not clear how to address the possibililty of having a 50 column (i.e. n=50) ind matrix as the prototype of subs2ind requires me to specify the indexes on by one.
Does anyone know how to deal with such scenario?
0 件のコメント
回答 (1 件)
madhan ravi
2020 年 9 月 30 日
p(sub2ind(size(p), ind(:, 1), ind(:, 2)) = Dayum % where RHS should be equal to size(ind)
4 件のコメント
madhan ravi
2020 年 9 月 30 日
編集済み: madhan ravi
2020 年 9 月 30 日
for k = 1 : size(ind, 1)
I = num2cell(ind(k, :))
p(sub2ind(size(p), I{ : }))= datum;
end
参考
カテゴリ
Help Center および File Exchange で Resizing and Reshaping Matrices についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!