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