Plot graphs at conclusion of a 'for loop'
1 view (last 30 days)
Show older comments
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?
0 Comments
Accepted Answer
Star Strider
on 11 Feb 2017
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.
More Answers (0)
See Also
Categories
Find more on Line Plots in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!