Why is "hold on" messing up my plot and how do i get rid of the straight line on 0
3 views (last 30 days)
Show older comments
The Excel file is a just a two column sheet of numbers, but i dont know why when i use hold on it puts my three *'s on 0? but at the proper y value. any ideas? Also there is a line on the x axis from 0-400any ideas on why that is?
thanks
t = (0:.002:1);
Vo = -.5;
Vi = .5;
tau = .2;
Vc = Vi + (Vo - Vi)* exp(-t/tau);
%Above is the theoretical equation and parameters.
x = xlsread('2_2.xlsx');
%this reads in excel file of measured points.
r = [1.43E-05 0.000580299 0.000186299];
c = [-0.4175 0.42798 0.08351];
%This is used to plot the three points.
figure(1)
plot(Vc,'green');
hold on
plot(x,'blue');
plot(r,c,'*');
title('Response of a first-order System');
legend('Theoretical','Measuured');
xlabel('Time');
ylabel('Volts');
0 Comments
Accepted Answer
Walter Roberson
on 12 Feb 2013
"hold on" still allows the axis limits to be automatically adjusted. If your values in your "x" variable (which you are plotting on the y axis) are large enough then your "y" axis will extend to 400.
Your plot of Vc and your plot of "x" are both plots of those values along the y axis, with the x axis being implicitly set to 1:max(length(Vc),size(x,1)). length(Vc) is 600. And your x/y pairs, r and c, are so much less than 600 that unless you zoom in, the coordinates are going to be squished against the y axis.
Remember, plotting with only one variable treats that variable as y values with the x being 1 to the number of rows (or 1 to the number of columns if the single variable was a column vector.)
Likewise when you plot(x) then because you only supply one variable, the first column of "x" will be treated as one line of "y" coordinates and x coordinate 1 to the number of rows of "x", and the second column will be treated as a second line of "y" coordinates and x coordinate 1 to the number of rows of "x". Be careful here in confusing the variable names and their position in the argument sequence (which is what determines the meaning assigned to the contents of the variable.)
0 Comments
More Answers (0)
See Also
Categories
Find more on Axis Labels in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!