필터 지우기
필터 지우기

Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

index out of bound

조회 수: 1 (최근 30일)
sweta arya
sweta arya 2016년 1월 20일
마감: MATLAB Answer Bot 2021년 8월 20일
intial_image=zeros(180,1);
for i=1:180
intial_image(i)=i;
end
y =zeros(30,1);
y = datasample(intial_image,30);
disp(y(2,1));
size3=0;
nBins=8;
Nind=0;
h1=0;
count=0;
for i=1:30
if(numel(y)==30)
jpgFileName = strcat('C:\Users\priya\Desktop\Fashion Photography\',num2str(y(i)), '.jpg');
I= imread(jpgFileName);
[row,col,m]=size(I);
size3=size3+ row*col;
count=count+1;
end
giving error:
can not access y(2,1) because numel(y)=1.
  댓글 수: 2
Stephen23
Stephen23 2016년 1월 20일
Please show us all of the error message. This means all of the red text.
Stephen23
Stephen23 2016년 1월 20일
The code needs to be simplified. Replace this:
initial_image=zeros(180,1);
for i=1:180
intial_image(i)=i;
end
with this:
initial_image = (1:180).';
There is no point in preallocating y like this:
y =zeros(30,1);
because it is completely reallocated on the very next line:
y = datasample(...)

답변 (1개)

Walter Roberson
Walter Roberson 2016년 1월 20일
Whatever
datasample(intial_image,30)
is, it is resulting in a scalar.
What is the result of
which -all datasample
? Is it from the Statistics Toolbox or does it resolve to one of your own routines?

이 질문은 마감되었습니다.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by