# Assign values to cell array which is preallocated with for loop

9 ビュー (過去 30 日間)
Dennis 2022 年 11 月 2 日

numEleIndexVector = length(freqIntervCntr); %11
numEleFreqFiltered = length(frequencyFiltered); %619
indexCell = cell(1,numEleIndexVector);
indexCell(1:numEleIndexVector) = {NaN(1,numEleFreqFiltered)};
%divider_freq = 0.05
for i = 0:(numEleIndexVector-1)
for j = 1:numEleFreqFiltered
if i == 0
indexCell{1,1+i} = find(frequencyFiltered(j) <= divider_freq);
else
indexCell{1,i+1} = find((divider_freq*(i)) < frequencyFiltered(j) & frequencyFiltered(j) <= (divider_freq*(i+1)));
end
end
end
Hey guys, I want to to find the indices which are meeting the defined conditions.
Also I would like to delete all of the NaN values left in the cell afterwards.
Grateful for any help!
##### 1 件のコメントなしを表示なしを非表示
Khushboo 2022 年 11 月 4 日
Hello,
Could you please give more details regarding what are the array values of frequencyFiltered? It would also be helpful if you could give an idea what exactly are you trying to do and the expected output.

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

### 回答 (1 件)

Santosh Fatale 2022 年 11 月 11 日
Hi Dennis,
I investigated the code provided by you, and below is the modified code that I think will achieve the desired output.
frequencyFiltered = randi(100, 619, 1);
numEleIndexVector = 11
numEleFreqFiltered = length(frequencyFiltered); %619
indexCell = cell(1, numEleIndexVector);
% indexCell(1:numEleIndexVector) = {NaN(1,numEleFreqFiltered)};
divider_freq = 2
for i = 0:(numEleIndexVector-1)
% Note that I removed the extra for loop here.
if i == 0
indexCell{1,1+i} = find(frequencyFiltered <= divider_freq);
else
indexCell{1,i+1} = find((divider_freq*(i)) < frequencyFiltered & frequencyFiltered <= (divider_freq*(i+1)));
end
end
You do not need internal loop with variable 'j', which was a part of the earlier code.

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

### カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

### Community Treasure Hunt

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

Start Hunting!

Translated by