creating subplot from function
2 次查看(过去 30 天)
显示 更早的评论
I have some code, generally looks like this:
x='dr_0.01.txt';
foo(x);
function y = foo(fname)
Do stuff
end
Ultimately, the function creates a figure. How can I load in other files with the x variable, run foo(x), and put each figure created from each call to function f into a subplot that is 2x2? So I want to load in 4 files, and call the function on all 4 files. Then create a subplot that contains all 4.
0 个评论
回答(1 个)
Chad Greene
2018-11-7
Looks like instead of x you meant to call that variable fname? If so, something like this:
fname = {'fname1.txt','fname2.txt','fname3.txt','fname4.txt'};
function y = foo(fname)
% Load and plot each dataset:
for k = 1:length(fname)
D = importdata(fname{k});
subplot(2,2,k)
y(k) = plot(D(:,1),D(:,2))
end
end
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!