• Регистрация
fatbad
fatbad 0.00
н/д

Как ускорить вычисления

03.06.2020
Коллеги, доброе утро Как ускорить код? for i=1:length(data1.gTruth.DataSource.Source) for j=length(data1.gTruth.DataSource.Source{i}):-1:1 if contains(data1.gTru...

Коллеги, доброе утро

Как ускорить код?

    for i=1:length(data1.gTruth.DataSource.Source)
     
        for j=length(data1.gTruth.DataSource.Source{i}):-1:1
        
            if contains(data1.gTruth.DataSource.Source{i}(j:end),'\')
                data1.gTruth.DataSource.Source{i}(j:end);
                folderName{i}=data1.gTruth.DataSource.Source{i}(1:j);
                break
            end
        end
    end
    
uniqName=unique(folderName)';
for i=1:length(uniqName)
    alternativePaths={[ uniqName{i}   dirWayOut ]};
    unresolvedPaths = changeFilePaths(data1.gTruth,alternativePaths);
end

 

Задача изменить путь к картинкам, но такой алгоритм считает долго 44000 сек. Как можно получить путь к файлу из следующей сроки

C:\Users\USER\Documents\Matlab\new_captcha_with_mounting_dots\New folder (2)\737515.526.png

Теги

      03.06.2020

      Комментарии

      • fatbad
        fatbad0.00
        3.06.2020 10:12

        пока сделал так:

        for j=length(data1.gTruth.DataSource{1}):-1:1
                j;
                if contains(data1.gTruth.DataSource{1}(j:end),'\')
                    
                    folderNameTemp=data1.gTruth.DataSource{1}(1:j);
                    break
                end
            end
            
            for i=1:length(data1.gTruth.DataSource)
                if contains(data1.gTruth.DataSource{i},folderNameTemp)
                    folderName{i}= folderNameTemp;
                else
                    for j=length(data1.gTruth.DataSource{i}):-1:1
                        j;
                        if contains(data1.gTruth.DataSource{i}(j:end),'\')
                            folderName{i}=data1.gTruth.DataSource{i}(1:j);
                            folderNameTemp=data1.gTruth.DataSource{i}(1:j)
                            break
                        end
                    end
                end
            end

        данные позволяют.

        второй вопрос был: как из C:\Users\USER\Documents\Matlab\new_captcha_with_mounting_dots\New folder (2)\737515.526.png поулчить C:\Users\USER\Documents\Matlab\new_captcha_with_mounting_dots\New folder (2)\? Есть ли какая-нибудь встроенная функция?