How do I remove empty indexes in a structure?

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?

 采纳的回答

No need for a loop in the first place:
refinedStats = stats([stats.Area] > 50);

3 个评论

Or you could remove them before regionprops() by calling bwareaopen() or bwareafilt(), though those may call regionprops internally.
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.

请先登录,再进行评论。

更多回答(0 个)

Community Treasure Hunt

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

Start Hunting!

Translated by