scaling down 0x axis coordinates of a graphic

조회 수: 2 (최근 30일)
kerozi
kerozi 2016년 5월 3일
답변: kerozi 2016년 5월 4일
Hello all,
I was wondering how to scale down, 50, 0x axis coordinates of a function that are between [0,100] interval to [0,1] interval without harming the spacing ratios of ascending coordinates.
For instance; vector's values are 0 1 2 3 4 5 6 7 8 9 10 and I want them to be in [0,1] interval. hence the values become 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 and 1.0.
Of course the easy answer would be just to multiply the answer by necessary coefficient (which is in this case 0.1). But I think there are a lot of better answers that I seek particularly.
And I'm sorry for language mistakes in advance.
A=logspace(1,0,50) %I created an initially dense 50 0x coordinates
B=exp(A) %then make it denser
C=B/1e+04 %and tried to make values smaller or tuck them into non specific interval.
Main purpose of this question is whether MATLAB can create an array vector between 0 and 1 with the element number of 50 or 100, with a scattered spacing from beginning '0' to end value '1'. For example: [ 0 0.0125 0.0250 0.0500 0.0750 0.1 0.1500 0.2 0.3 0.45 0.575 0.6 0.650 0.700 0.7250 0.750 0.775 0.8 0.8250 0.850 0.875 0.9 0.9125 0.9250 0.950]
So sorry for long post. If there are something vague term. I'd happy to answer.
Thank you so much for even considering to answer.

답변 (3개)

J. Webster
J. Webster 2016년 5월 3일
편집: J. Webster 2016년 5월 3일
Is this what you're looking for?
x = 1:.5:56; %example initial array with spacing of 1/2 from 1 to 56
%subtract the first value from the entire array so that it now starts at 0
x = x-x(1);
%now divide the array by the value of the last point, so that the entire thing will go 0 to 1;
x = x./x(end);
  댓글 수: 1
kerozi
kerozi 2016년 5월 3일
This is not the particular answer that I am looking for but it definitely expanded the horizon. This codes' problem was the differences between x values were uniform. '0.091'. But as I said definitely expanded the view because it keeps the number of points same but it limits the xmin and xmax with a coefficient. Thank you for answering my delusional question.

댓글을 달려면 로그인하십시오.


Azzi Abdelmalek
Azzi Abdelmalek 2016년 5월 3일
Look at this example
t=0:100;
y=sin(t);
plot(t,y)
xl=xlim;
xtn=0:0.125:1
set(gca,'xtick',linspace(xl(1),xl(2),numel(xtn)))
xtln=arrayfun(@(x) num2str(x),xtn,'un',0)
set(gca,'xticklabel',xtln)
  댓글 수: 1
kerozi
kerozi 2016년 5월 4일
Yet again it creates the array with a uniformly spaced way. 0 to 100 interval turned out to be 0 to 1 interval, which is really good. But the the spacing is 'uniform', 0.125. Not the way I want it to be.
'with a scattered spacing from beginning '0' to end value '1''

댓글을 달려면 로그인하십시오.


kerozi
kerozi 2016년 5월 4일
Mr Abdelmalek's code scaled down the array s interval uniformly spaced way which is a good thing thus I problems first phase is complete but the spacing should ve been denser at the beginning, as if its an array like [0 0.0125 0.025 0.0375 ... 0.8 0.9 1] .

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by