Hello, I really want to know if there is any function or tool that I can use to give diferents names to diferents variables. I'm studying any features (like area, values of pixel, ecc..) of somes regions in an image, and then I want to save these, and here I have the problem. if I woul to save, for example: image 1: region1: num of object=...; area=...; centroid:... region2: num of object=...; area=... image 2:..... How can I "name", or "appoint" diferents features or image in order that I study it? Because I want to save all in a file without overwrite... I don't know if I explain it very well, but thank you

 채택된 답변

Guillaume
Guillaume 2015년 1월 19일

1 개 추천

While you can generate variable names on the fly (using eval), it's not a good idea as it makes the code harder to understand, harder to debug, harder to check for syntax error and slower to execute.
In your case, what I would do is create structure arrays:
%hypothetical processing code
for imgindex = 1 : numimages
img = loadimage(imgindex); %load an image
numregions = regioncount(img); %get number of region
for regionindex = 1 : numregions
[area, centroid] = regionproperties(img, regionindex); %get property of region
%HERE is where you store the result in structure arrays:
imageprops(imgindex).region(regionindex).area = area;
imageprops(imgindex).region(regionindex).centroid = centroid;
end
end
To access the area of the 5th region of the 3rd image:
area = imageprops(3).region(5).area;

댓글 수: 3

Maria
Maria 2015년 1월 21일
ok, thanks. At the end, I did it in this way (the way you say). I was asking because I thought that saving in different variables would be more efficient, faster to execute, ecc... But you said the opposite, so thank you!! I have another question that maybe you can help me. I have 2 differents functions (created by me) with small differences, how can I see which one is faster? or more efficient? Maybe you know how thank you!!
Guillaume
Guillaume 2015년 1월 21일
As of R2014, the simplest way to compare functions is to use timeit. If you require more help start a new question.
Maria
Maria 2015년 1월 22일
Thank you!

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

추가 답변 (0개)

카테고리

질문:

2015년 1월 19일

댓글:

2015년 1월 22일

Community Treasure Hunt

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

Start Hunting!

Translated by