필터 지우기
필터 지우기

Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

I have troubles to plot several functions in one diagram.

조회 수: 1 (최근 30일)
Philipp Mueller
Philipp Mueller 2016년 10월 21일
마감: MATLAB Answer Bot 2021년 8월 20일
I want to plot several functions and lines with different ranges (domains) in one diagram. I have a stair-step curve and to this stair-step i want to add some other curves. But it does not work. (I know the command hold on / hold off).
fplot(@(x) exp(x),[1000 1000000],'b')% this function does not work
plot([1000000,60],[9000000,60]);% straight line %does not work
And now my "special code":
%https://de.mathworks.com/help/matlab/ref/fplot.html
clear all
clc
Input_Matrix_Woehler = textread('2.txt')
x1 = Input_Matrix_Woehler(:,1)
y1 = Input_Matrix_Woehler(:,2)
[xb,yb] = stairs(x1,y1);
%line([100000 60], [900000 60],'Color','r','LineWidth',23);
plot([1000000,60],[9000000,60]);% straight line %does not work
hold on
figure1 = figure('Name','Woehler',...
'Color',[0.756862759590149 0.866666674613953 0.776470601558685]);
axes1 = axes('Parent',figure1);
hold(axes1,'on');
xlim(axes1,[1000 200000000]);
box(axes1,'on');
grid on;
set(axes1,'Color',[0.894117653369904 0.941176474094391 0.901960790157318],...
'XMinorTick','on','XScale','log');
plot(yb,xb)
hold on;
fplot(@(x) exp(x),[1000 1000000],'b')% this function does not work
hold off

답변 (1개)

Adam
Adam 2016년 10월 21일
편집: Adam 2016년 10월 21일
Your use of an explicit axes handle is good:
hold(axes1,'on');
xlim(axes1,[1000 200000000]);
box(axes1,'on');
but why aren't you using this throughout. In particular, what exactly 'does not work' about:
plot([1000000,60],[9000000,60]);
?
This works fine for me, although it should come with an explicit axes handle to be sure of where it is being plotted. I don't know where yours will be plotted since the instruction comes before your explicit axes creation. Either it will create a new figure or just plot on whatever figure you happened to already have open and in focus last.
Your fplot code produces nothing visible because the answer is Inf for every value in the range.
Even exp(100) gives
2.68811714181614e+43
so clearly exp evaluated between 1000 and 1000000 is going to be Inf

이 질문은 마감되었습니다.

태그

Community Treasure Hunt

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

Start Hunting!

Translated by