set xticks by calculation but also force 0 to be displayed
Ältere Kommentare anzeigen
I am setting xticks manually based on user inputs for distance. The plot will span the distance range; for example -1.3E-06 to 1.3E-06. The calculation works well to calculate the distance between tick marks, but depending on how it's done it may or may not automatically included 0 on the x axis. Is there a way I can force 0 to be displayed on the axis without altering my method for calculating the distance between tick marks.
Akzeptierte Antwort
Weitere Antworten (1)
Joel Lynch
am 10 Jun. 2021
Bearbeitet: Joel Lynch
am 10 Jun. 2021
set(gca,’XTick’,array_of_values)
2 Kommentare
Robert Demyanovich
am 10 Jun. 2021
Walter Roberson
am 10 Jun. 2021
ismember(0, vector_of_values)
but that leaves the searching open in that form. But if the vector is sorted you could
idx = find(vector_of_values <= 0, 1, 'last')
if vector_of_values(idx) == 0
exact match for 0
else
vector_of_values = [vector_of_values(1:idx), 0, vector_of_values(idx+1:end)]
end
assuming row vector
... But the union() approach I posted is much more compact and has the same effect.
Kategorien
Mehr zu Creating and Concatenating Matrices finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

