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

조회 수: 5 (최근 30일)
SL
SL 2016년 10월 23일
답변: Gowtham Uma M Jaganathan 2016년 10월 27일
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
Gowtham Uma M Jaganathan 2016년 10월 27일
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에서 Graphics Object Properties에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by