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!