Assign values to cell array which is preallocated with for loop
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentario
Khushboo
el 4 de Nov. de 2022
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.
Respuestas (1)
Santosh Fatale
el 11 de Nov. de 2022
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 comentarios
Ver también
Categorías
Más información sobre Loops and Conditional Statements en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!