saving the output arrays in for loop
조회 수: 2 (최근 30일)
이전 댓글 표시
I need to save the value of TrnPatches for every iteration in for loop and display it How can I do that?
Here is the code:
clc;
clear all;
close all
TrnImgPath='G:\Master_Students\Iman\UIUC\PNGImages\TrainImages\';
TrnPatches=[];
PatchWidth=8;
PatchHeight=8;
NImgs=100;
for i=1:NImgs
I=imread([TrnImgPath 'pos-' num2str(i) .PNG']);%Reading positive Pictures
I=im2double(I);%Convert image to double precision
TrnPatches=[TrnPatches;im2col(I,[PatchHeight,PatchWidth],'sliding')'];
%why the size changes
% imshow(TrnPatches,[]);
disp(i);
disp(TrnPatches);
end
댓글 수: 0
답변 (3개)
Jan
2014년 9월 30일
편집: Jan
2014년 9월 30일
Insert these lines:
filename = fullfile(TrnImgPath, sprintf('Picture%d.mat', i));
save(filename, TrnPatches);
By the way: You find a lot of help when you ask your favorite internet search engine for "Matlab save files in a loop". The forum is more powerful when you take the chance to examine the already discussed topics.
댓글 수: 2
Image Analyst
2014년 9월 30일
Here, look at this. Then you'll be able to find out whether there's a problem with i, or filename or something else. As long as i is not empty and TrnIMgPath is not empty, then filename cannot be empty. I think if filename were empty, then save() would throw an error. So I have my doubts about what you say, like you're running somewhat different code than what Jan gave. So you're doing something wrong that can be figured out by stepping through and examining variables.
Andrei Bobrov
2014년 9월 30일
one way
cd G:\Master_Students\Iman\UIUC\PNGImages\TrainImages
n = dir('pos-*.PNG');
name1 = {n.name};
nn = numel(name1);
TrnPatches = cell(nn,1);
for ii = 1:nn
I = imread(name1{ii});
TrnPatches{ii} = im2col(im2double(I),[8,8],'sliding').';
end
Image Analyst
2014년 9월 30일
What are you doing with im2col? I never use that function. And why are you concatenating all the images and wanting to save an ever growing image at each iteration?
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!