向量化Matlab循环更快

时间:2018-10-12 10:07:07

标签: arrays matlab

我有以下非常慢的matlab循环。我正在尝试按像素进行分类并在此处生成热图。关于如何使循环更快的任何建议?如何向量化数组?预先感谢。

im1_full = imread(img);

hmap1a=0*im1_full(:,:,1);
hmap1b=double(0*im1_full(:,:,1));
hmap1c=double(0*im1_full(:,:,1));

for i11=1:10:size(im1_full,1)-460-1
    i11
    for j11=1:10:size(im1_full,2)-700-1
        %FOR DEBUGGING
        %j11
        % This is used for bag of features
        tmp1=im1_full(i11:i11+460-1,j11:j11+700-1,:);
        [labelIdx, scores]= predict(categoryClassifier, tmp1);
        hmap1a(i11,j11)= labelIdx;
        hmap1b(i11,j11)=scores(1);
        hmap1c(i11,j11)=scores(2);

    end
end
toc;

1 个答案:

答案 0 :(得分:-1)

很好尝试harish!如果我是你,我将执行以下操作:

                var nodedbs = (from dnb in fp.DataNodeBase
                              join res in fp.Results on dnb.DataNodeBase_Id equals res.DataNodeBase_Id into dnbres
                              from res in dnbres.DefaultIfEmpty()
                              join queryres in fp.DataNodeQueryResult on res.Results_Id equals queryres.Results_Id into nodeandquery
                              from queryres in nodeandquery.DefaultIfEmpty()
                              where (dnb.Nodes_Id == operatorstation.OperatorStation_Id)
                              && ((dnb.IsNull("Family") ? "" : dnb.Family).Contains("File Compare") == false)
                               select new {
                                  NodeID = dnb.Nodes_Id,
                                  ResultsDataNodeBaseID = (res == null ? -1 : res.DataNodeBase_Id),
                                  NodeDataBaseNodeID = dnb.DataNodeBase_Id,
                                  DataNodeQueryResults = (queryres == null ? -1 : queryres.Results_Id)
                              }).ToArray();

将最大大小放在循环之外时,它将防止重新计算每次迭代的最大迭代限制。