I have a vector of 256 data points which is equal to 0.8 ms in total. How do I set the scale from 0 to 0.8, with steps for example of 0.2?

Réponses (2)

HWIK
HWIK le 15 Jan 2022

0 votes

Try this:
set(gca, 'XTick', 0:0.2:0.8)

6 commentaires

Sebastian Daneli
Sebastian Daneli le 15 Jan 2022
Does not work, all the numbers end up to the far left.
Star Strider
Star Strider le 15 Jan 2022
Perhaps:
set(gca, 'XTick', 0:0.2:0.8, 'XScale','log')
.
Sebastian Daneli
Sebastian Daneli le 15 Jan 2022
Modifié(e) : Sebastian Daneli le 15 Jan 2022
No, does not work.
It works quite nicely. And while I do not have your data, it is easy enough to make a plot.
x = linspace(0,0.8,256); y = sin(x);
plot(x,y,'-')
set(gca, 'XTick', 0:0.2:0.8)
If all you tell people is that something does not work, then you will need to explain just what about the plot I have created is not exactly what you requested?
Star Strider
Star Strider le 15 Jan 2022
@Sebastian Daneli — Please define what ‘does not work’ means in your previous Comment.
I completely failed Mind Reading 101 as an undergraduate, and as the result decided to major in Chemistry instead. It was easier.
John D'Errico
John D'Errico le 15 Jan 2022
Yes, but mind reading is soooo much more fun!

Connectez-vous pour commenter.

Image Analyst
Image Analyst le 16 Jan 2022

0 votes

Use the xticks(0:0.2:0.8) function:
Full demo:
% Create sample data.
x = linspace(0, 0.8, 256);
period = 0.2;
y = sin(2 * pi * x / period);
plot(x, y, 'b-', 'LineWidth', 3)
grid on
% Current tick marks are 0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8.
% Make them 0, 0.2, 0.4, 0.6, 0.8 using the xticks() function:
xticks(0 : 0.2: 0.8)
It replaces the old set(gca, 'XTick', 0:0.2:0.8) way of doing it (since r2016b).

Catégories

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by