我有一个由features表示的3D数组。feature的每个元素都是一个数字x。现在我将得到这个数字,并计算这个数字的g(x)和f(x) (g和f是x的函数)。我的问题是如何在N和f(x)之间求出绝对值的最大值。该函数将返回一个带有N元素x的数组。但我不知道怎么弄到它们。你能帮我一下吗?
这是我的密码:
%features is 3D array
%N is elements that we need
%Fs,sigmas,thetas are size of the array
% return N elements of features that maximization abs(f_s-g_s)
function features_filter=gabor_sort(features,N,Fs,sigmas,thetas)
for k = 1:numel(sigmas)
for j = 1:numel(Fs)
for i = 1:numel(thetas)
x= features(:,:,k,j,i);
f_x=x.^2;
g_x=x.^3+1;
s1=abs(f_x-g_x);
%%Do something in here to get maximization of s1
end
end
end
end发布于 2014-08-06 03:03:52
这不是问题。创建两个矩阵,存储我们为sigma, Fs和theta的每个组合获得的特性,并将每个特性的绝对值放在这个矩阵中,完成后,按降序排序这些距离。然后,我们可以使用sort的第二个参数来给出最大距离的特征的位置。换句话说,这样做:
%features is 3D array
%N is elements that we need
%Fs,sigmas,thetas are size of the array
% return N elements of features that maximization abs(f_x-g_x)
function features_filter=gabor_sort(features,N,Fs,sigmas,thetas)
s1 = []; % s1 array to store our distances
xFeatures = []; %// Features to return
for k = 1:numel(sigmas)
for j = 1:numel(Fs)
for i = 1:numel(thetas)
x = features(:,:,k,j,i);
xFeatures = cat(3,xFeatures,x); %// Stack features in a 3D matrix
x = x(:); %// Convert to 1D as per your comments
f_x=mean(x.^2); %// Per your comment
g_x=mean(x.^3+1); %// Per your comment
s1 = [s1 abs(f_x-g_x)]; %// Add to s1 array
end
end
end
[~,sortInd] = sort(s1, 'descend');
%// Return a 3D matrix where each slice is a feature matrix
%// The first slice is the one that maximized abs(f_x - g_x) the most
%// The second slice is the one that maximized abs(f_x - g_x) the second most, etc.
features_filter = xFeatures(:,:,sortInd(1:N));次要注意事项:此代码未经测试。我无法访问你的数据,所以我无法复制。希望这行得通!
https://stackoverflow.com/questions/25151387
复制相似问题