フィルターのクリア

Store arrays of different size in each for loop itertaion

1 回表示 (過去 30 日間)
Turbulence Analysis
Turbulence Analysis 2024 年 4 月 10 日
編集済み: Matt J 2024 年 4 月 11 日
Hi,
In the below script, I need to store the output kkkk into a new array but in the same column. Here, size of the kkkk is different during each itertaion.
I know that cell array would solve the issue. But I need to store them in the single colum.
for i=1:4
kkkk = find(A>=sz(i,1) & A<=sz(i,1)+100);
clear kkkk
end
  1 件のコメント
James Tursa
James Tursa 2024 年 4 月 10 日
Can you show a small example of inputs and desired output?

サインインしてコメントする。

採用された回答

Matt J
Matt J 2024 年 4 月 10 日
kkk=cell(4,1);
for i=1:4
kkkk{i} = find(A>=sz(i,1) & A<=sz(i,1)+100);
end
kkkk=vertcat(kkkk{:});
  5 件のコメント
Turbulence Analysis
Turbulence Analysis 2024 年 4 月 11 日
Hi Stephen,
I corrected the varibale name and preallocated the cell array correctly. Still the processing time is very large.
Matt J
Matt J 2024 年 4 月 11 日
I corrected the varibale name and preallocated the cell array correctly. Still the processing time is very large.
If you profile the code, I think you will see that the bottleneck is coming from find(), not from anything else. It's an expensive function.

サインインしてコメントする。

その他の回答 (1 件)

Matt J
Matt J 2024 年 4 月 11 日
編集済み: Matt J 2024 年 4 月 11 日
b=sparse(sz(:,1)');
kkkk = nonzeros( (A(:)>=b & A(:)<=b+100).*(1:numel(A))' );
  1 件のコメント
Turbulence Analysis
Turbulence Analysis 2024 年 4 月 11 日
編集済み: Matt J 2024 年 4 月 11 日
Hi,
This command leading to out of memory issue.
Requested 179528104x9700 (13288.7GB) array exceeds maximum array size
preference (15.4GB). This might cause MATLAB to become unresponsive.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by