How to store individual return value of a function

6 次查看(过去 30 天)
I want to store individeual return values to a variable
The code is as follows:
function tri=imageReadFromFolder()
something!
tri=[z,distance,angle];
end
As can be seen it basically reads set of images from a folder and for each image it will have individual 'z,distance,angle' .But after it reads it only shows the result for the last images.
Any help on how to solve this will be highly appreciated.
  2 个评论
Jan
Jan 2019-4-25
编辑:Jan 2019-4-25
The question is not clear. What is "something!"? Where does "z,distance,angle" come from? It cannot be seen (especially not "basically"), that a set of images is read here. There is no code to read images, there I cannot guess, why the data of the "last" image are replied only. Most likely you use a loop and write:
for k = 1:numel(images)
img = import_image()
z = fcn(Img)
end
instead of
z(k) = fcn(Img)
% ^^^
Please edit your question and post some working code, which reproduces the problem. If we guess, what the problem is, the answers will be more or less unrelated.
Tipu Sultan
Tipu Sultan 2019-4-26
I am giving you the whole code:
function tri=imageReadFromFolder()
D = 'C:\Users\Tipu_Standard\Desktop\testIMAGES';
S = dir(fullfile(D,'Original*.jpg')); % pattern to match filenames.
for i = 1:numel(S)
F = fullfile(D,S(i).name);
I = imread(F);
B = rgb2gray(I);
A=adapthisteq(B);
% Display the original image
figure,imshow(A);
distance =0;
angle=0;
rmin=8;
rmax=30;
% Find all the circles with radius >= 8 and radius <= 30
[centersdark,radiidark] = imfindcircles(A,[rmin rmax],'Objectpolarity','dark','Sensitivity',0.913);
k=numel(radiidark);
viscircles(centersdark,radiidark ,'EdgeColor','b');
if(k==0)
z=0;
else
z=1;
p=2*radiidark;
f=2.1;
w=62;
h=144;
s=2.88;
distance=(f*w*h)/(p*s);
a=(192/2)-centersdark(1);
b=144-centersdark(2);
angle=atan2(a,b)*(180/pi);
end
tri=[z,distance,angle];
end
end

请先登录,再进行评论。

采纳的回答

KALYAN ACHARJYA
KALYAN ACHARJYA 2019-4-26
编辑:KALYAN ACHARJYA 2019-4-26
Inputs in Main script help to change the input easily.
Main scripts:
D = 'C:\Users\Tipu_Standard\Desktop\testIMAGES';
S = dir(fullfile(D,'Original*.jpg')); % pattern to match filenames.
for i = 1:numel(S)
F = fullfile(D,S(i).name);
I = imread(F);
% Next line changes required, k{i}, I missed the account the size of function output please check the below @Stephen Comment
k(i)=fun1(I);
end
Here k gives the values of individual images, like k(1),k(2)...
Make the different function file
function tri=fun1(I)
B=rgb2gray(I);
A=adapthisteq(B);
% Display the original image
figure,imshow(A);
distance =0;
angle=0;
rmin=8;
rmax=30;
% Find all the circles with radius >= 8 and radius <= 30
[centersdark,radiidark] = imfindcircles(A,[rmin rmax],'Objectpolarity','dark','Sensitivity',0.913);
k=numel(radiidark);
viscircles(centersdark,radiidark ,'EdgeColor','b');
if(k==0)
z=0;
else
z=1;
p=2*radiidark;
f=2.1;
w=62;
h=144;
s=2.88;
distance=(f*w*h)/(p*s);
a=(192/2)-centersdark(1);
b=144-centersdark(2);
angle=atan2(a,b)*(180/pi);
end
tri=[z,distance,angle];
end
  9 个评论

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Matched Filter and Ambiguity Function 的更多信息

产品


版本

R2015a

Community Treasure Hunt

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

Start Hunting!

Translated by