Borrar filtros
Borrar filtros

How to loop multiple images in a subplot?

5 visualizaciones (últimos 30 días)
Talha Anwer
Talha Anwer el 14 de Feb. de 2019
Comentada: Bob Thompson el 18 de Feb. de 2019
I've saved 4 pictures in 4 variables that means 4 pictures per variable. I'd like to subplot all those pictures (16 pictures) in a loop. Kindly, help me through this.
  2 comentarios
Bob Thompson
Bob Thompson el 14 de Feb. de 2019
When you do your calling of subplot, you can enter your loop index as the third input.
for i = 1:something
...
subplot(4,4,i);
...
end
Talha Anwer
Talha Anwer el 14 de Feb. de 2019
Editada: Talha Anwer el 14 de Feb. de 2019
Thanks for answering the question. Can you please more specify it?
I tried this earlier it's not working with my code:
My code:-
a=imread('eight.tif');
j=imnoise(a,'salt & pepper', 0.02);
k=imnoise(a,'gaussian',0, 0.002);
l=imnoise(a,'speckle', 0.002);
b=[5 5;9 9;15 15;30 30];
for i=1:4
h=fspecial('average', b(i));
c=imfilter(a,h,'replicate');
c1=imfilter(j,h,'replicate');
c2=imfilter(k,h,'replicate');
c3=imfilter(l,h,'replicate');
for j=1:16
subplot(1,4,j);
(What to write here. I mean how to plot c, c1, c2 and c3?)
end
end

Iniciar sesión para comentar.

Respuesta aceptada

Bob Thompson
Bob Thompson el 14 de Feb. de 2019
Editada: Bob Thompson el 14 de Feb. de 2019
There are some small adjustments to be made for this to work. Also, I'm not sure what you want to plot your 'c' variables against, so you will need to change the 'x' values in the plot command with something else.
for i = 1:4;
h=fspecial('average', b(i));
c{i,1} = imfilter(a,h,'replicate'); % It's better to index variables rather than creating variables with numeric names. Matlab is much much easier to work with this way. Curly braces indicate cells
c{i,2} = imfilter(j,h,'replicate');
c{i,3} = imfilter(k,h,'replicate');
c{i,4} = imfilter(l,h,'replicate');
figure(i)
for j = 1:4; % NOTE: You CANNOT use 'j' for both the variable and the loop. Change one of them
subplot(1,4,j) % Creates a row of four plots per figure
plot(x,c{i,j});
end
end
  3 comentarios
Talha Anwer
Talha Anwer el 18 de Feb. de 2019
Editada: Talha Anwer el 18 de Feb. de 2019
for cosiderring my question. Actually in 'c' variables images are stored and I want them to be plotted in subplots not against any value 'x' and sixteen plots in one figure. This code is actually showing an error like this (Screenshot attached):
Kindly have a look at that:
Bob Thompson
Bob Thompson el 18 de Feb. de 2019
What do you mean by 'showing an error'? Is there a specific error message, or are you indicating that you are having troubles producing the output you want. I'm assuming the latter, since your posted image looks like it isn't properly plotting the additional subplots. Did you properly index the sub plot command? Is it producing the correct number of figures?

Iniciar sesión para comentar.

Más respuestas (0)

Community Treasure Hunt

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

Start Hunting!

Translated by