How do I update a struct array in a for loop?

조회 수: 19 (최근 30일)
Mark Lepage
Mark Lepage 2017년 9월 11일
편집: Stephen23 2017년 9월 12일
I am determining the equivalent diameter of circles in a series of images.
My code is as follows:
for k = 1:20
I = imread(k);
BW = im2bw(I);
stats = regionprops(BW,'EquivDiameter');
end
I would like the stats struct array to update the values so I get a summary of all the analyzed equivalent diameters, instead of just the last image which is what my code is giving me now. Any ideas?
Thanks,
Mark

채택된 답변

Stephen23
Stephen23 2017년 9월 11일
편집: Stephen23 2017년 9월 11일
Just use indexing to put the data into a non-scalar structure:
stats(k) = ...
  댓글 수: 4
Mark Lepage
Mark Lepage 2017년 9월 12일
편집: Mark Lepage 2017년 9월 12일
This works well to get all my data into one variable (C{})
So this is an improvement on what I was doing before.
What I am hoping for is that my list generated by stats can be continuously updated with my results as they are generated.
i.e. regionprops generates equivalent diameter values, which will change for every image. I want a single list, that will include the equivalent diameters for every image that is analyzed. Hopefully with the data in one single column.
Your method works well, but each image results are stored in a different column, which will be time consuming to analyze afterwards.
To explain better what I am trying to do, I want to measure the equivalent diameters of bubbles in my images, and then calculate a bubble size distribution from the results of all the images.
Stephen23
Stephen23 2017년 9월 12일
편집: Stephen23 2017년 9월 12일
@Mark Lepage: if the data within C all have suitable sizes, you can certainly concatenate it into one structure afterwards:
cat(N,C{:}) % pick N for the dimension to concatenate along
Note that converting into one structure is a good idea, as it makes accessing the fields very convenient:
"To explain better what I am trying to do..."
It really doesn't matter to me if you are measuring bubbles or elephant ears: a cell array is a cell array, and a structure is a structure regardless. If you really wanted help you would give information about your data: what sizes it has, exactly the output you need, and you would upload some samples.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Data Type Conversion에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by