How to transform/scale data with XLim adjusted x axis range in plot?

5 次查看(过去 30 天)
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

回答(1 个)

Gowtham Uma M Jaganathan
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.

类别

Help CenterFile Exchange 中查找有关 Shifting and Sorting Matrices 的更多信息

标签

产品

Community Treasure Hunt

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

Start Hunting!

Translated by