For Loop Problem error

조회 수: 3 (최근 30일)
shalaw faraj
shalaw faraj 2019년 7월 15일
댓글: shalaw faraj 2019년 7월 15일
img=imread('C:\Users\Shalaw\Downloads\gray.jpeg');
[n,m]=size(img);
part1=img(1:n/2,1:m/2);
part2=img(1:n/2,(m/2)+1:end);
part3=img(n/2+1:end,1:m/2);
part4=img(n/2+1:end,m/2+1:end);
for i=1:4
subplot(2,2,i);
imshow(part1); -----> I want to change 1 to i, but i cant please help.
end
  댓글 수: 1
Stephen23
Stephen23 2019년 7월 15일
편집: Stephen23 2019년 7월 15일
Simply use a cell array with indexing:
Putting numbers into variable names is a sign that you are doing something wrong. In most cases using indexing is simpler, neater, and much more efficient.

댓글을 달려면 로그인하십시오.

채택된 답변

Adam
Adam 2019년 7월 15일
img=imread('C:\Users\Shalaw\Downloads\gray.jpeg');
[n,m]=size(img);
part{1}=img(1:n/2,1:m/2);
part{2}=img(1:n/2,(m/2)+1:end);
part{3}=img(n/2+1:end,1:m/2);
part{4}=img(n/2+1:end,m/2+1:end);
for i=1:4
subplot(2,2,i);
imshow(part{i});
end
  댓글 수: 1
shalaw faraj
shalaw faraj 2019년 7월 15일
very helpful thanks.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Andrei Bobrov
Andrei Bobrov 2019년 7월 15일
img=imread('C:\Users\Shalaw\Downloads\gray.jpeg');
[n,m]=size(img);
imgs = mat2cell(img,[n,n]/2,[m,m]/2)';
for ii = 1:4
subplot(2,2,ii);
imshow(imgs{ii});
end
  댓글 수: 3
Andrei Bobrov
Andrei Bobrov 2019년 7월 15일
k = 4;
[n,m]=size(img);
imgs = mat2cell(img, n/k*ones(1,k), m/k*ones(1,k))';
for ii = 1:k^2
subplot(k,k,ii);
imshow(imgs{ii});
end
shalaw faraj
shalaw faraj 2019년 7월 15일
I am very sorry, but I want to find (mean, max, min, std, entropy) for each block and using for but it is not working please help. thanks again.
img=imread('C:\Users\Shalaw\Downloads\gray.jpeg');
[n,m]=size(img);
part{1}=img(1:n/2,1:m/2);
part{2}=img(1:n/2,(m/2)+1:end);
part{3}=img(n/2+1:end,1:m/2);
part{4}=img(n/2+1:end,m/2+1:end);
for i=1:4
subplot(2,2,i);
imshow(part{i});
Xmean{i}=mean(part{i});
Xmax{i}=max(part{i});
Xmin{i}=min(part{i});
Xstd{i}=std(part{i});
Xentropy{i}=entropy(part{i});
end

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by