Undefined Variable f as i am trying to extract the features
이전 댓글 표시
clc
clear
close all
format compact
face_folder='pos/';
folder_content=dir([face_folder,'*']);
face=size (folder_content,1);
for k=3:face
k1=k-2
string=[face_folder,folder_content(k,1).name];
image=imread(string);
f(k1,:)=cohog(image);
end
face=face-2;
x=[f(1:face,:);]';
y=[ones(face,1);]';
save testinria x y face
This is my code through which i want to extract the features, but while executing the program it shows error as
Undefined variable f.
I have defined f within the for loop, then why it's showing this error, please help me to rectify the error.
Error in feature1 (line 15)
x=[f(1:face,:)]';
댓글 수: 1
Image Analyst
2012년 10월 11일
편집: Image Analyst
2012년 10월 11일
Are you absolutely 100% sure it entered the loop?
채택된 답변
추가 답변 (2개)
Image Analyst
2012년 10월 11일
0 개 추천
You need to preallocate f before the loop - at least one row. In your line it doesn't know how many columns there are and it needs to if you're going to assign it like that.
댓글 수: 3
Walter Roberson
2012년 10월 11일
No, when an array does not exist, and ":" is used as an index, then MATLAB will create the array with as many columns as is needed to fit the data being assigned.
Image Analyst
2012년 10월 11일
So, assuming it entered the loop like he says it definitely did, why didn't it create the array f? Instead of saying it was not defined yet, why didn't it just define/create it? I couldn't run the code because I don't have cohog.
My guess would be that it never did enter the loop so by the time it gets to x=[f..... there is no f yet. But he says it was defined in the loop. I wonder if Muzafar knows how to use the debugger.
By the way Muzafar, don't use "image" as the name of your variable - that will blow away the "image()" function that is built in to MATLAB.
Muzafar Pandit
2012년 10월 12일
카테고리
도움말 센터 및 File Exchange에서 MATLAB에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!