creating subplot from function
8 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (1)
Chad Greene
am 7 Nov. 2018
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
1 Kommentar
Siehe auch
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!