Assign values to cell array which is preallocated with for loop
조회 수: 3 (최근 30일)
이전 댓글 표시
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.
For information about function "find" and "cell", check out following links.
댓글 수: 0
참고 항목
카테고리
Help Center 및 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!