about dynamic variable name for output
古いコメントを表示
Hi there, In the code below I want dynamic outputs for 'k' value in the loop. For instance if c=2 I want to get region_number1,region_number2,locs1, locs2 for the output. How can I do this?
for k=1:c
[region_number,locs]=find_region_pixels(first_order_big(:,:,k),orig_image);
end
3 件のコメント
While it is possible, creating dynamic variable names will make your code slow and buggy:
Learn to use indexing, which is fast, simple, and reliable:
region_number = NaN(1,c);
locs = NaN(1,c);
for k = 1:c
[region_number(k),locs(k)] = find_region_pixels(first_order_big(:,:,k),orig_image);
end
Change the output size and/or class (e.g. cell array) to suit the outputs of that function.
Huseyin
2016 年 12 月 17 日
Walter Roberson
2016 年 12 月 17 日
region_number = NaN(1, c);
locs = cell(1, c);
for k = 1:c
[region_number(k),locs{k}] = find_region_pixels(first_order_big(:,:,k),orig_image);
end
回答 (2 件)
1 件のコメント
Image Analyst
2016 年 12 月 17 日
Yes, you can use regionprops, which will measure those things. Then put the results into a cell array:
for k = 1 : numberOfImages
thisLabeledImage = first_order_big(:,:,k);
% Ask for PixelList, which is a list of all (x,y) points that are white/true/1 in the labeled image.
props = regionprops(thisLabeledImage ,orig_image, 'PixelList');
% There may be more than one blob in the image, so props is a structure array.
% For this image, just store this image's blobs' coordinates into a cell array for use later.
blobPixels{k} = props(k);
end
カテゴリ
ヘルプ センター および File Exchange で Image Arithmetic についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!