I have a problem with a plot

조회 수: 1 (최근 30일)
salvatore liberto
salvatore liberto 2016년 10월 21일
답변: Pawel Jastrzebski 2017년 12월 20일
Hi everyone, i have a function that depends by a parameter. I plot this function and i save this plot with the command save. When i change the parameter, i want to show both functions in the same plot.. How can i do?

답변 (2개)

Thorsten
Thorsten 2016년 10월 21일
plot(x, y1);
hold on
plot(x, y2)
or
plot(x, y1, x, y2)

Pawel Jastrzebski
Pawel Jastrzebski 2017년 12월 20일
clear all;
clc;
x = 1:10; % x values
parameter = [2 3 4]; % number of parameters i.e 3
fig = figure % create a figure windos
hold on; % keep adding plots to the existing figure window
for i=1:length(parameter) % execute loop as many times as the number of the parameters
y = x.^parameter(i); % calculate the function value for given parameter
plot(x,y); % plot the function
name = ['Figure-', num2str(i), '.png']; % create the name for the file
% SET THE SIZE OF THE .PNG FILE
set(fig,...
'PaperPosition', [0 0 16 9], ...
'PaperUnits' , 'centimeters'...
);
saveas(fig,name); % save the figure to a file
% REPEAT ALL STEPS UNTIL THE END OF LOOP
end

카테고리

Help CenterFile Exchange에서 Creating, Deleting, and Querying Graphics Objects에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by