How to solve Index exceeds matrix dimensions?
1 次查看(过去 30 天)
显示 更早的评论
Hello, can anybody please give me advices how to solve this: I have 3 images and I would like to noise this images with 2 kind of noise and save to cell array. When I have cell array 3x3 it works well. It looks like this:
clc, clear all, close all
a = imread ('mri1.jpg')
b = imread ('mri2.png')
im3 = imread ('mri3.jpg')
im1 = rgb2gray (a)
im2 = rgb2gray (b)
pole = {im1 false false ;
im2 false false ;
im3 false false }
[n,m]=size(pole);
for i = 1 : m
for j = 1 : n
if j == 2
pole{i,2} = imnoise (pole{i,1},'salt & pepper',0.02);
end
end
end
for i = 1 : m
for j = 1 : n
if j == 3
pole{i,3} = imnoise (pole{i,1},'salt & pepper',0.1);
end
end
end
But when I decided to give to cell array next column (where I would like to save other kind of noise) it collaps with error: Index exceeds matrix dimensions. It looks like:
clc, clear all, close all
a = imread ('mri1.jpg')
b = imread ('mri2.png')
im3 = imread ('mri3.jpg')
im1 = rgb2gray (a)
im2 = rgb2gray (b)
pole = {im1 false false false;
im2 false false false;
im3 false false false}
[n,m]=size(pole);
for i = 1 : m
for j = 1 : n
if j == 2
pole{i,2} = imnoise (pole{i,1},'salt & pepper',0.02);
end
end
end
for i = 1 : m
for j = 1 : n
if j == 3
pole{i,3} = imnoise (pole{i,1},'salt & pepper',0.1);
end
end
end
for i = 1 : m
for j = 1 : n
if j == 4
pole{i,4} = imnoise (pole{i,1},'gaussian',0.1,0.01);
end
end
end
How should I solve this?
0 个评论
回答(1 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!