Saving to a new file each time
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
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
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.
The best way to produce unique identifiers is the following :
fname=sprintf('myalgo%i.mat',sum(floor(1000*clock))
Thus the ID of the file changes every millisecond ...
Best AL
精彩评论