pre allocating variables in matlab
조회 수: 2 (최근 30일)
이전 댓글 표시
i have this block of code but when i access elements, they are not arranged properly
x=zeros(1,10000);
y=zeros(1,10000);
count=1;
for i=1:rows
for j=1:columns
if imgThresh(i,j)==0
y(count)=rows-i+1;
x(count)=j;
count=count+1;
break
end
end
end
nonzeros(x)
nonzeros(y)
댓글 수: 2
James Tursa
2021년 3월 3일
You need to give us a small example of input and desired output. Please describe specifically what it is about the output of your current code that you don't like. What are you trying to do?
답변 (1개)
Walter Roberson
2021년 3월 4일
That's not what I get.
imgThresh = im2bw(imread('image.png'));
rows = size(imgThresh,1);
columns = size(imgThresh,2);
x=zeros(1,10000);
y=zeros(1,10000);
count=1;
for i=1:rows
for j=1:columns
if imgThresh(i,j)==0
y(count)=rows-i+1;
x(count)=j;
count=count+1;
break
end
end
end
plot(x,y)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!