How to loop multiple images in a subplot?
5 ビュー (過去 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 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!