How to loop multiple images in a subplot?
5 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Talha Anwer
am 14 Feb. 2019
Kommentiert: Bob Thompson
am 18 Feb. 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 Kommentare
Bob Thompson
am 14 Feb. 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
Akzeptierte Antwort
Bob Thompson
am 14 Feb. 2019
Bearbeitet: Bob Thompson
am 14 Feb. 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 Kommentare
Bob Thompson
am 18 Feb. 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?
Weitere Antworten (0)
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!