How to loop multiple images in a subplot?
4 次查看(过去 30 天)
显示 更早的评论
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 个评论
Bob Thompson
2019-2-14
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
采纳的回答
Bob Thompson
2019-2-14
编辑:Bob Thompson
2019-2-14
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 个评论
Bob Thompson
2019-2-18
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?
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Subplots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!