Plot graphs at conclusion of a 'for loop'

조회 수: 1 (최근 30일)
MK96
MK96 2017년 2월 11일
댓글: Star Strider 2017년 2월 11일
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.
  댓글 수: 2
MK96
MK96 2017년 2월 11일
This worked, thanks
Star Strider
Star Strider 2017년 2월 11일
My pleasure.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Line Plots에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by