如何使用GPU运行以下Matlab代码?

时间:2019-05-19 17:38:55

标签: matlab gpu

我想通过GPU运行Matlab代码,如何转换以下代码以便它可以访问GPU?

我试图进行转换,但是当我在语法中使用gpuarray而不获取数据时,我正在获取对象实例。

如何解决此问题? 如有可能,请转换以下代码。

path1 = 'C:\Data\For new Paper3\TUM_GAID_Gait_Analysis\AEI_PEI\';
list1 = dir(path1);                       
fName1 = {list1.name};
[~,y1] = size(fName1);

cv111=[];

for f_no=3:y1
    path2 = char(strcat(path1,fName1(f_no),'\'));
    list2 = dir(path2);                       
    fName2 = {list2.name};
    [~,y2] = size(fName2);
    fName1(f_no)
    path2
    y2
    numberOfPose=0;
    for ff_no=3:3
        path3 = char(strcat(path2,fName2(ff_no),'\'));
        list3 = dir(path3);                       
        fName3 = {list3.name};
        [~,y3] = size(fName3);
        numberOfPose = (y3-2)/10;        
    end 
    cv11=[];
    for num=1:numberOfPose
        train = double([]);
        group1 = cell(1,1);
        group2 = cell(1,1);
        for ff_no=3:y2
            path3 = char(strcat(path2,fName2(ff_no),'\'));
            list3 = dir(path3);                       
            fName3 = {list3.name};
            [~,y3] = size(fName3);
            for fff_no=2+(num)
                group1{1} = [group1{1},(ff_no-2),(ff_no-2)];
                path4 = char(strcat(path3,fName3(fff_no)));              
                image = double(imread(path4));
                temp1=image(:);
                train=[train; temp1';temp1'];
            end   
        end  

        [coeff,score,~,~,explained] = pca(train);            
        sm = 0;
        no_components = 0;
        for k = 1:size(explained,1)
            sm = sm+explained(k);
            if sm <= 99.4029
               no_components= no_components+1;
            end
        end
        m = mean(train,1);
        mat1 = score(:,1:no_components);  
        cv1=[];        
        num
        for ff_no=3:y2
            path3 = char(strcat(path2,fName2(ff_no),'\'));
            list3 = dir(path3);                       
            fName3 = {list3.name};
            [~,y3] = size(fName3);
            for fff_no=numberOfPose*1+2+(num)
                group2{1} = [group2{1},(ff_no-2)];
                path4 = char(strcat(path3,fName3(fff_no)));
                image = double(imread(path4));
                Img_mean = double(image(:)')-m;
                Img_proj = Img_mean*coeff;
                test=Img_proj(:,1:no_components);
                prob1=double([]);
                [x,y]=size(train);
                class = classify(test,mat1,group1{1},'diaglinear');
                cv1=[cv1;class];                
            end   
        end      
        cv11=[cv11,cv1];             
    end
    cv111=[cv111,cv11];
end

0 个答案:

没有答案