Build array from descriptive data without a loop
古いコメントを表示
I want to go from
Array1 = [10,3,3;1000,178,4];
to
Array2 = [10;13;16;1000;1178;1356;1534];
without using
Idx2 = 1;
Array2 = zeros(sum(Array1(:,3)),1);
for Idx1 = 1:size(Array1,1)
Array2(Idx2:Idx2+Array1(Idx1,3)-1) = [Array1(Idx1,1),Array1(Idx1,1)+[1:Array1(Idx1,3)-1].*Array1(Idx1,2)];
Idx2 = Idx2+Array1(Idx1,3)-1;
end
Help?
採用された回答
その他の回答 (1 件)
Array1 = [10,3,3;1000,178,4];
Array2 = cumsum(Array1,2)
2 件のコメント
Walter Roberson
2023 年 2 月 17 日
Tthe third column is the number of elements to generate, with the difference being the second column, and the starting point being the first column.
Kevin Holly
2023 年 2 月 17 日
ah, thanks for pointing that out.
カテゴリ
ヘルプ センター および File Exchange で Image Arithmetic についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!