Array size decreases with every iteration
古いコメントを表示
Hi,
I have an array A of size 500,000 x 1
I want to make multiple new arrays by dropping the 1st row, 2nd row, 3rd row etc.
Basically I want a new array B of size 499,999 x 1 which is equal to A(n+1:end,1)
and then a new array C of size 499998 x 1 which is equal to A(n+2:end,1)
etc...
To do this, I have the follow for loop:
i=50;
New_Array = zeros(500000,i);
for n = 1:i
New_Array(n:end-1,n) = A(n+1:end-n,1);
end
The issue is because I preallocated, the rows that it drops off get filled with '0'. I don't want this because I need to multiply A*New_Array and I don't want the dropped off rows with 0's.
If i remove the preallocation, I get an error "The end operator must be used within an array index expression."
I think it's because the array size keeps getting smaller and smaller with every iteration.
How can I fix this?
Thanks!
2 件のコメント
James Tursa
2021 年 2 月 9 日
編集済み: James Tursa
2021 年 2 月 9 日
Can you show us MATLAB code or pseudo code that takes your inputs, does all of your calculations, and produces the desired output including all of your downstream multiplies? We might be able to suggest a different way to accomplish the end result that is faster and/or uses less memory.
JD
2021 年 2 月 10 日
採用された回答
その他の回答 (1 件)
カテゴリ
ヘルプ センター および 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!