Storing multiple value in array without overriding.
이전 댓글 표시
Below is the code snippet, where I am selecting images one by one, converting a image in 30*30 patch and calculating the standard deviation of patch and then storing that value in excel sheet. But the problem is only the standard deviation of last image is being saved to excel sheet others value are getting over ridden. How to avoid that?
Directory = 'With MA\';
%Imgs = dir(fullfile(Directory,'*.jpg'));
Imgs = dir(Directory);
nfiles = length(Imgs); % Number of files found
for z=1:nfiles
thisname = Imgs(z).name;
thisfile = fullfile(Directory, thisname);
try
Img = imread(thisfile);
%Img = imread(fullfile(Directory,Imgs(z).name));
I=Img(:,:,2);
imSz = size(I);
patchSz = [30 30];
xIdxs = [1:patchSz(2):imSz(2) imSz(2)+1];
yIdxs = [1:patchSz(1):imSz(1) imSz(1)+1];
patches = cell(length(yIdxs)-1,length(xIdxs)-1);%for patches
stan = cell(length(yIdxs)-1,length(xIdxs)-1);%for standard deviation
for i = 1:length(yIdxs)-1
Isub = I(yIdxs(i):yIdxs(i+1)-1,:);
for j = 1:length(xIdxs)-1
patches{i,j} = Isub(:,xIdxs(j):xIdxs(j+1)-1);%saving patches
stan{i,j} = std2(patches{i,j});%saving standard deviation
end
end
catch
end
xlswrite('output.xlsx', stan);
end
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Characters and Strings에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!