scaling down 0x axis coordinates of a graphic
1 次查看(过去 30 天)
显示 更早的评论
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.
0 个评论
回答(3 个)
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);
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)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!