Info

This question is closed. Reopen it to edit or answer.

I have troubles to plot several functions in one diagram.

1 view (last 30 days)
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

Answers (1)

Adam
Adam on 21 Oct 2016
Edited: Adam on 21 Oct 2016
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

Tags

Community Treasure Hunt

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

Start Hunting!