How to store individual return value of a function
8 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Tipu Sultan
el 25 de Abr. de 2019
Comentada: Tipu Sultan
el 26 de Abr. de 2019
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 comentarios
Jan
el 25 de Abr. de 2019
Editada: Jan
el 25 de Abr. de 2019
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.
Respuesta aceptada
KALYAN ACHARJYA
el 26 de Abr. de 2019
Editada: KALYAN ACHARJYA
el 26 de Abr. de 2019
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 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Matched Filter and Ambiguity Function en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!