How to transform/scale data with XLim adjusted x axis range in plot?
6 views (last 30 days)
Show older comments
Code where the first figure has ranges 0x1 and 0x100, respectively for x-axis and y-axis; expected range for the second figure is 0x1 and 0x10 for the axes. So I want to transform the data from x-axis 0x100 to 0x10 in accordance with the `XLim`
close all; clear all; clc;
% http://stackoverflow.com/a/21529536/54964
u = rand(1,100);
f = figure;
hax = axes(f);
plot(u, 'Parent', hax);
% range 0x1 and 0x100.
f2 = figure;
hax2 = axes(f2);
plot(u, 'Parent', hax2);
set(hax2,'XLim',[0 10]);
I think there has to be done some transformations and scaling of the data. I would like to do this by some standard methods because I do not want to lose any piece of information. I would love to have some generic method for this because I have to do the basic thing so many times.
MATLAB: 2016b OS: Debian 8.5
0 Comments
Answers (1)
Gowtham Uma M Jaganathan
on 27 Oct 2016
My understanding is that you want to change the X-axis limits while maintaining the consistency to data points.
You can do this by changing the "XData" property of the line plot. For example replace the last line in your code with the line below:
hax2.Children.XData = linspace(0,10,length(hax2.Children.XData));
Refer the documentation page below for more information on "XData" and other area properites.
0 Comments
See Also
Categories
Find more on Graphics Object Properties in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!