HELP I'm a complete beginner! Is it possible to create a loop within a function?
古いコメントを表示
Hi! I'm a complete MATLAB beginner and have been stuck with this problem for the past 48 hours.
I have a variable "templates" which is an array 58x2x240 - it basically consists of 58 X and Y coordinates for face landmark locations of 240 faces - both male and female.
I have a second variable "sex" whis is a vector (or matrix??) 1x240 - it basically contains the numbers 0 and 1 - 0 for male face, 1 for female face. It corresponds to the faces in the "templates" array.
I'm supposed to make a function to average the templates for the male faces. So basically get a 58x2 matrix that has the average X and Y coordinates of the 120 male faces. My problem at this stage is that I can't figure out how to use the "sex" variable to sort out only the male faces in the "templates" array. Do I have to create a loop? If so, should the loop be inside the function? This is what I've tried:
function[average]=averageFace(templates, sex, gender)
%btw I have no idea what the variable "gender" could be, but the assignment
%says the function should take as input "an array containing all the
%templates; a vector specifying, in order the gender of each template; the
%gender to average over, 0 for males, 1 for females."
for loop = 1:240
image=templates(:,:,loop);
maleFace=Image(gender==0);
end
%there would obviously be more stuff here - I just haven't gotten to that yet
end
My idea was that this should give me an array 58x2x120 of only the rows that correspond to 0 in the "sex" vector. It doesn't seem to be working at all!
If someone could PLEASE help me I would be forever grateful! I have no idea if I'm even on the right track here.
4 件のコメント
Azzi Abdelmalek
2012 年 10 月 24 日
Andrea, make your question brieve and clear, you will have more chance to get an answer.
Andrea
2012 年 10 月 24 日
Jan
2012 年 10 月 25 日
I've applied code-formatting. Please, Andrea, learn how to format code in this forum.
It seems like the question is re-opened again.
These could be reasons for closing the question:
- I cannot find a relation between the title "Is it possible to create a loop within a function?" and the question.
- The question is not really clear, but a discussion would probably result in more clarifications.
- As long as "code on its own" does not make sense to the author, a discussion in a Matlab forum seems to be inappropriate. I'm convinced that "thinking in words" is not a successful strategy for solving a Matlab course.
And as usual my personal opinion: I detest automatic face recognition, because it let machines control the freedom of human. When I take into account, that my bank is not able to offer something more sophisticated than a 4 digits PIN code to secure my money, I do not want to allow even less public systems to scan my face. Some day I will get an email: "Hi, we have registered that you perform a jogging session each Thursday in the park, but not today. Please contact a physician if you feel ill. Otherwise we have to increase the fees of your health insurance...". But of course such realistic or naive considerations are not a valid reason for closing a thread.
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Semantic Segmentation についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!