How to set the plot start to zero ? I have some measurements. On the x label, they start from 0 to 6, but from 1 I can see something change on

8 commentaires

Are you passing in x data when you plot() ?
ylim([90 150])
xlim([0.5 5.5])
set(findobj(gcf,'Type','legend'),'Location','best')
Salt to suit...
Since the Q? wasn't asked in the body but tried to jamb into the title, we don't know for sure what the rest was intended to be -- nor do we have the code that created the figure to see exactly how was drawn.
BUT, another reading is if it is wanted that the x axis actually go from 0 to N, then would have to have an X variable in the plot() call as well as just the Y array; it looks like the above may have used the latter form in which case the ordinal value of the points is used as the independent variable.
But, since there are only five (5) points, then the values would go from 0-4 and that's not commensurate with the x label of "(0 to 5.12 sec)" because array indices can only be integer-valued. Hence, one presumes there must be some other time vector needed that may have been implicitly calculated or assumed -- but, insufficient evidence is presented to know for sure.
Thank you sir,however still it isn't what I want. It starts from 1 but I want it begin from 0 .
What I shall do?
NB: what
>> 1:5.12
ans =
1 2 3 4 5
>>
returns -- the integers from 1:5 as the default colon step interval is 1 when not given.
What you want for x is still totally unknown for sure; all we have to go on is the code given -- if it doesn't produce what you think it should or want it to, you'll have to tell us what it is that is wanted instead; we can't read intent, only code.
@Shimelis Abebe, Your wrote:
>> but still I doesn't get the heart of my problem.
Could you post the code that you used to generate the figure in a Code Block (not an picture of the code). Include the data in Throughput matrix so that the code will run and repeat your figure. Then tell us exactly what you need the figure to look like. Keep in mind that when you refer to "5.12 sec", you need to explain which data is associated with that time. To generalize, all of your data is associated with times, so make sure that you explain the time-value associated with every data point you have.
See the "CODE" section above the post - and the left square icon says "Insert a line of code". Click it and then enter the source code there. If there is a Run button when you do that (a green triangle pointing to the right, just to the left of the "Help" button), then hit that Run button, and you should see the figure that your code generates.
Dear Paul Hoffrichter thank you very much and I appreciate any time you give me.
Could please share your email address? here is my email address shmels.gabe@wu.edu.et
Kind regards,
Shimelis.
Dear Shimelis, I am assuming that you wish to discuss this problem further and need additional assistance. Since my time is extremely limited due to work and study obligations, I hope you will ask another question. As a community, we will all take a look and try to help you further.
Best Regards, Paul

Connectez-vous pour commenter.

 Réponse acceptée

Here is some made up data to illustrate one approach:
x = [ 0 1.1 2 3.3 5.12];
y = [146 145.9 145.8 139 128;
133 132.8 132 114 133;
119 118 116 102 133 ];
plot(x, y, '-bo')

Plus de réponses (4)

Like the previous answer said: be sure to plot x values AND y values. MATLAB allows you to plot data in the form:
data = rand(10,1); % Create 10 random points
plot(data); % Plot ONLY the y values - the x-values default to the indices of y
But this plots the data versus its index, in this case from 1 to 10. Yes, this is confusing because the plotting works, but the x-values are missing!
The plot command is normally used with x AND y values. For example, let's say the x-axis values associated with the data are from 0.1 to 1, incrementing by 0.1. Then we can plot the results as:
% Create a column of x data starting at 0.1 up to 1,
% incrementing by 0.1 (the ' symbol converts the row data to column)
xdata = (0.1:0.1:1)';
% Create the random y data column using the rand command
ydata = rand(10,1)
% Plot x versus y
plot(xdata,ydata);
You can modify the plot command, specify a figure, etc. Type "help plot" to learn more about this powerful and probably most often used MATLAB command.
x=[0:size(Throughput,2)-1].'; % generate temporary x vector for convenience from 0
hL=plot(x,1E-6*Throughput(1:4,;).'); % plot first four rows of array as columns
salt to suit.
If there are only 4 rows in Throughput, then can dispense with the indexing expression entirely.
plot() will treat each column in the Y argument if an array as a separate variable; hence the transpose. Saves the explicit reference to have to plot each individually.
See the documentation for plot for all the syntax options; saving the line handles in hL lets you adjust line properties as desired.
Thank you very much for your great help me dear all
Dear Mr Paul Hoffrichter based on your lightful answer I try it semmes what I want but still I dis't geat the heart of my problem.
I wrote the code as given bellow image what is my fualt?
First of all, you should be aware that the following two expressions are equivalent:
>> 1:5.12
ans =
1 2 3 4 5
>> 1:5
ans =
1 2 3 4 5
Are you just wanting to label the axis from 0:4 instead of 1:5? If so, then this works:
figure(2)
x = 0:4;
plot(x, Throughput./1e6);
legend('0.5 m/s','1 m/s','1.5 m/s','2 m/s');
xlabel('TTT_{W-L} index (0 sec to 5.12 sec)');
ylabel('Throughput)');
axis([0 5 -inf inf]);
hold off
grid on
box on
The left figure is from your original program. The right figure, is figure(2) from the code in this post.

Produits

Version

R2021a

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by