Hey there! I tried plotting a simple function using two ways:
  1. By creating an anonymous function and using fplot() to produce the plot
  2. By simply creating a normal function and using plot() to produce the plot
Here's the code for the first:
clear all
close all
clc
M = 100;
p_b = 2;
Q = @(p_a) M./(p_a + p_b);
figure(1)
fplot(Q, [0 35])
ylim([0 30])
xlim([0 25])
Here's the code for the second:
clear all
close all
clc
M = 100;
p_b = 2;
p_a = [0:0.1:35];
Q = M./(p_a+p_b);
figure(2)
plot(Q,p_a)
ylim([0 30])
xlim([0 25])
The curves look identical but they're actually different if you use the data tips on the figures and compare them (see photo below)
Anyone know why this is? I'm a bit lost :(

 채택된 답변

Torsten
Torsten 2023년 4월 5일

0 개 추천

plot(p_a,Q)
instead of
plot(Q,p_a):
M = 100;
p_b = 2;
Q = @(p_a) M./(p_a + p_b);
hold on
fplot(Q, [0 35])
ylim([0 30])
xlim([0 25])
p_a = [0:0.1:35];
Q = M./(p_a+p_b);
plot(p_a,Q)
hold off
grid on

댓글 수: 2

PCR_7
PCR_7 2023년 4월 6일
My god, 'twas such a simple fix... Thank you so much! So plot and fplot just have x & y the opposite way?
Torsten
Torsten 2023년 4월 6일
편집: Torsten 2023년 4월 6일
plot(x-values,y-values)
fplot(function handle or symbolic function of x,[minimum x-value maximum x-value])

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Line Plots에 대해 자세히 알아보기

제품

릴리스

R2020b

태그

질문:

2023년 4월 5일

편집:

2023년 4월 6일

Community Treasure Hunt

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

Start Hunting!

Translated by