How do I use a matrix in a For Loop Iteration

Hi!
I am trying to run a for loop to get all my iterations completed. So the M and N values need to change at the same time. The issue is everytime I try changing the code I either am getting an error about how the function has to have scalar values or when I fix that then go to the second iteration I am going to i = 2 which is not the next number in my M values. I feel like this is a very basic fix but I cant figure it out!
Very Greatful if someone could help me out with this!
type = 'gaussian';
M = I(:,1);
N = I(1,:);
for i = M
M = M(i);
for j = N
N = N(i);
R = imnoise2(type,M(i),N(i))
R(i) = R;
end
end

Respuestas (1)

DGM
DGM el 10 de Abr. de 2022
Editada: DGM el 10 de Abr. de 2022
There are undefined variables and functions being used. M, N, and R are all being overwritten, and there are likely array size mismatches in the assignments. Nobody can fix this unless they know what it's supposed to do.
type = 'gaussian';
M = I(:,1); % I is undefined
N = I(1,:);
for i = M
M = M(i); % you immediately overwrite your vector
for j = N
N = N(i); % you immediately overwrite your vector
R = imnoise2(type,M(i),N(i)); % what is this function? you're overwriting R
R(i) = R; % LHS is a scalar, RHS is ostensibly an array??
end
end
If you're trying to apply noise to an image with imnoise(), then:
inpict = imread('cameraman.tif');
R = imnoise(inpict,'gaussian',0,0.01);
imshow(R)
If you're trying to do something different, then you'll have to explain what you're trying to do and what the undefined functions and variables are.

Categorías

Productos

Etiquetas

Preguntada:

el 10 de Abr. de 2022

Editada:

DGM
el 10 de Abr. de 2022

Community Treasure Hunt

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

Start Hunting!

Translated by