How to append a 3D array inside a parfor in matlab?
조회 수: 3 (최근 30일)
이전 댓글 표시
I have several gray-scale images and I want to store that in a 3d array(hieghtXwidthXnumber-of-images) in matlab.
my code looks like this
train_img = [];
parfor i=1:100
a = imread(image-file);
a1 = imresize(a, 0.5);
b = rgb2gray(a1);
d = im2double(b);
train_label = [train_label;p];
train_img = cat(3,train_img(:,:,:),d);
end
Error: The temporary variable train_img in a parfor is uninitialized. See Parallel for Loops in MATLAB, "Uninitialized Temporaries".
In the above code the parfor i=1: 100, I don't know whats the upper limit of loop. Its decided at run time. Could anybody let me know what this error means and how to overcome this?
댓글 수: 0
답변 (1개)
Walter Roberson
2016년 6월 16일
You should be writing the array to train_img{i} instead of trying to do the cat(3). After the parfor you can run through the cell array and find the largest image and pad everything out to that size and write it all to a 3D array.
Alternately you could write to train_img(:,:,i) in the parfor loop, but only if you also added code that handles the possibility that the images are not all the same size.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Parallel for-Loops (parfor)에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!