Plot graphs at conclusion of a 'for loop'

1 vue (au cours des 30 derniers jours)
MK96
MK96 le 11 Fév 2017
Commenté : Star Strider le 11 Fév 2017
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?

Réponse acceptée

Star Strider
Star Strider le 11 Fév 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.
  2 commentaires
MK96
MK96 le 11 Fév 2017
This worked, thanks
Star Strider
Star Strider le 11 Fév 2017
My pleasure.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Line Plots dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by