I am not understanding the error "Undefined function or variable all_images" I currently have the following code;
조회 수: 1 (최근 30일)
이전 댓글 표시
function stimuli=letters_load(N, randord)
dirname= 'C:\Users\User\Documents\MATLAB\stimuli';
if~exist('N','var')
N=21;
end
if N<1 | N>21
error('Number of images selected is out of range')
end
if~exist('randord','var')
randord=false;
end
d=dir([dirname '*.jpg']);
for i=1:length(d)
file=[ dirname d(i).name ];
all_images{i}=imread(file);
end
if randord
idx=randperm(21);
img = all_images(idx(1:N));
else
img = all_images;
end
댓글 수: 0
답변 (1개)
Walter Roberson
2019년 1월 22일
편집: Walter Roberson
2019년 1월 22일
You only assign into all_images if length(d) is at least 1.
In other words, the result of the dir() was empty.
Note that the result of
[dirname '*.jpg']
is going to be
'C:\Users\User\Documents\MATLAB\stimuli*.jpg'
You should switch to using fullfile():
fullfile(dirname, '*.jpg')
also you should pre-allocate:
all_images = cell(length(d), 1);
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Motor Control Blockset에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!