about dynamic variable name for output

조회 수: 1 (최근 30일)
Huseyin
Huseyin 2016년 12월 17일
편집: Stephen23 2019년 6월 19일
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
Huseyin
Huseyin 2016년 12월 17일
first_order_big has multidimensional data inside. So this code gives me an error like: "In an assignment A(:) = B, the number of elements in A and B must be the same."
How can I fix this?
Walter Roberson
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개)

Stephen23
Stephen23 2016년 12월 17일
편집: Stephen23 2019년 6월 19일
  댓글 수: 1
Jan
Jan 2016년 12월 17일
편집: Jan 2016년 12월 17일
100 votes from me.
@Mathworks: Please let this answer appear whenever a user types the terms "dynamic" and "variable" in one sentence.

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


Image Analyst
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

카테고리

Help CenterFile Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by