Plot graphs at conclusion of a 'for loop'

2 次查看(过去 30 天)
I am currently producing the following 2 graphs inside a for loop:
% LogPriceReturn Graph
figure(1); % opens a new figure for graph
x = Timestep; % sets x axis equal to the 'Timestep'
y = LogPriceReturn; % sets y axis equal to the 'LogPriceReturn'
plot(x,y, 'Marker','o', 'MarkerFaceColor','black'); hold on % plots graph of x and y, using 'hold on' command to retain each loop result
title('Log Price Return'); % sets the title of graph
xlabel('Timestep'); % sets x-axis label of graph
ylabel('Log Price Return Graph'); % sets y-axis label of graph
axis([1 n -1 1]); % formats axis limits
% StockPrice Graph
figure(2) % opens a new figure for graph
x = Timestep; % sets x axis equal to the 'Timestep'
y = StockPrice; % sets y axis equal to the 'StockPrice'
plot(x,y, 'Marker','o', 'MarkerFaceColor', 'black'); hold on % plots graph of x and y, using 'hold on' command to retain each loop result
title('Stock Price'); % sets the title of graph
xlabel('Timestep'); % sets x-axis label of graph
ylabel('Stock Price'); % sets y-axis label of graph
axis([1 n -inf inf]); % formats axis limits
When I run the code I can see the figures immediately as they update with each loop.
Is there a way I can only see the figures once the code has run? i.e. at the end?

采纳的回答

Star Strider
Star Strider 2017-2-11
For my purposes here (and since you didn’t post it), I’m using ‘k’ as the loop index. So assume this loop:
for k = ...
% LogPriceReturn Graph
x1(k) = Timestep; % sets x axis equal to the 'Timestep'
y1(k) = LogPriceReturn; % sets y axis equal to the 'LogPriceReturn'
x2(k) = Timestep; % sets x axis equal to the 'Timestep'
y2(k) = StockPrice; % sets y axis equal to the 'StockPrice'
end
figure(1); % opens a new figure for graph
plot(x1,y1, 'Marker','o', 'MarkerFaceColor','black'); hold on % plots graph of x and y, using 'hold on' command to retain each loop result
title('Log Price Return'); % sets the title of graph
xlabel('Timestep'); % sets x-axis label of graph
ylabel('Log Price Return Graph'); % sets y-axis label of graph
axis([1 n -1 1]); % formats axis limits
% StockPrice Graph
figure(2) % opens a new figure for graph
plot(x2,y2, 'Marker','o', 'MarkerFaceColor', 'black'); hold on % plots graph of x and y, using 'hold on' command to retain each loop result
title('Stock Price'); % sets the title of graph
xlabel('Timestep'); % sets x-axis label of graph
ylabel('Stock Price'); % sets y-axis label of graph
axis([1 n -inf inf]); % formats axis limits
NOTE This is UNTESTED CODE. It should work, but may require minor modification.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Title 的更多信息

产品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by