首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何求满足条件的三维矩阵的N个值

如何求满足条件的三维矩阵的N个值
EN

Stack Overflow用户
提问于 2014-08-06 02:34:57
回答 1查看 111关注 0票数 1

我有一个由features表示的3D数组。feature的每个元素都是一个数字x。现在我将得到这个数字,并计算这个数字的g(x)f(x) (gf是x的函数)。我的问题是如何在Nf(x)之间求出绝对值的最大值。该函数将返回一个带有N元素x的数组。但我不知道怎么弄到它们。你能帮我一下吗?

这是我的密码:

代码语言:javascript
复制
%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
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-08-06 03:03:52

这不是问题。创建两个矩阵,存储我们为sigma, Fstheta的每个组合获得的特性,并将每个特性的绝对值放在这个矩阵中,完成后,按降序排序这些距离。然后,我们可以使用sort的第二个参数来给出最大距离的特征的位置。换句话说,这样做:

代码语言:javascript
复制
%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));

次要注意事项:此代码未经测试。我无法访问你的数据,所以我无法复制。希望这行得通!

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25151387

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档