How to loop multiple images in a subplot?
5 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Talha Anwer
le 14 Fév 2019
Commenté : Bob Thompson
le 18 Fév 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 commentaires
Bob Thompson
le 14 Fév 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
Réponse acceptée
Bob Thompson
le 14 Fév 2019
Modifié(e) : Bob Thompson
le 14 Fév 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 commentaires
Bob Thompson
le 18 Fév 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?
Plus de réponses (0)
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!