每次保存到一个新文件 [英] Saving to a new file each time

查看:103
本文介绍了每次保存到一个新文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以前,我编写了用于执行LBP的代码.我面临的问题是,我需要每次从直方图获取数据时都使用一个不同的文件,而不是每次都使用相同的文件.我该怎么做?需要一些指导.下面的代码是我为LBP编写的代码.

previously i wrote a code for execution of LBP. The problem i face is that i need to the data from the histogram a different file each time and not the same file each time. How do i do it? Need some guidance over it. The code is below is the one i have written for LBP.

%% LBP
scale = 2.^[7 6 5; 0 -inf 4; 1 2 3]; 
for i=2:6:m-1
    for j=2:6:n-1
        for k=i:i+6
           for l=j:j+6
             J0=I2(i,j);
             I3(i-1,j-1)=I2(i-1,j-1)>J0;
             I3(i-1,j)=I2(i-1,j)>J0;
             I3(i-1,j+1)=I2(i-1,j+1)>J0; 
             I3(i,j+1)=I2(i,j+1)>J0;
             I3(i+1,j+1)=I2(i+1,j+1)>J0; 
             I3(i+1,j)=I2(i+1,j)>J0; 
             I3(i+1,j-1)=I2(i+1,j-1)>J0; 
             I3(i,j-1)=I2(i,j-1)>J0;
             LBP(i,j)=I3(i-1,j-1)*2^7+I3(i-1,j)*2^6+I3(i-1,j+1)*2^5+I3(i,j+1)*2^4+I3(i+1,j+1)*2^3+I3(i+1,j)*2^2+I3(i+1,j-1)*2^1+I3(i,j-1)*2^0;
           end
        end
        LBP=uint8(LBP);
        LBPv=reshape(LBP,1,size(LBP,1)*size(LBP,2));
        Hist=hist(LBPv,0:255);
        save('C:\Users\Lakshmen\Documents\MATLAB\HistInf','Hist');
    end
end

推荐答案

您可以创建一个计数器变量,每次调用SAVE函数时该计数器变量都会增加.您可以使用此计数器通过附加计数器来生成文件名.

You can create a counter variable which you increment each time you call the SAVE function. You would use this counter to generate filenames by appending it.

BASE_DIR = 'C:\Users\Lakshmen\Documents\MATLAB';

counter = 1;
for i=..
    for j=...
        Hist = hist(..);

        fname = sprintf('HistInf%03d.mat', counter);
        save(fullfile(BASE_DIR,fname), 'Hist');
        counter = counter + 1;
    end
end

否则,您可以只使用单元格数组在每次迭代中保存值,然后最后将此变量保存到单个MAT文件中.

Otherwise, you can just use a cellarray to save the values at each iteration, then save this variable into a single MAT-file at the end.

这篇关于每次保存到一个新文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆