Plot graphs at conclusion of a 'for loop'

1 Ansicht (letzte 30 Tage)
MK96
MK96 am 11 Feb. 2017
Kommentiert: Star Strider am 11 Feb. 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?

Akzeptierte Antwort

Star Strider
Star Strider am 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.
  2 Kommentare
MK96
MK96 am 11 Feb. 2017
This worked, thanks
Star Strider
Star Strider am 11 Feb. 2017
My pleasure.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Line Plots finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by