I have a structure generated by the "regionprops" function for image processing.
I ran the following code to remove unwanted regions:
n = numel(stats);
for i=1:n
if stats(i).Area > 50
refinedStats(i,:) = stats(i);
end
end
This gives me a structure with the desired indexes, however the indexes of the ones I removed remain, just with their fields as [].
I was wondering how I remove these indexes from the structure?

 Respuesta aceptada

Guillaume
Guillaume el 24 de Feb. de 2016
No need for a loop in the first place:
refinedStats = stats([stats.Area] > 50);

3 comentarios

Image Analyst
Image Analyst el 24 de Feb. de 2016
Or you could remove them before regionprops() by calling bwareaopen() or bwareafilt(), though those may call regionprops internally.
David Cynamon
David Cynamon el 24 de Feb. de 2016
Thank you very much! Worked perfectly.
I'm trying to plot the depths at which chlorophyll reaches max. This I did by indexing. But there are some indexes which show []. These correspond to those points where chlorophyll values are missing. How do I remove those indices []. Please help me! My code is as follows.
for i=1:size(chla,2)
idx = find(chla(:,i)==max(chla(:,i)));
idx = idx(1);
idx_valy(i)= Y(idx,i);
end
The idx=idx(1) is because at some points the max value of chlorophyll occured at two depths so I took only one depth.
Thank you in advance.

Iniciar sesión para comentar.

Más respuestas (0)

Preguntada:

el 24 de Feb. de 2016

Comentada:

el 17 de Mzo. de 2020

Community Treasure Hunt

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

Start Hunting!

Translated by