how to shift position of an index of max value to origo in matlab?
2 次查看(过去 30 天)
显示 更早的评论
Hi, I would like to shift the position the maximum value so that the maximum value is at the center, i.e. at origo.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/191230/image.png)
7 个评论
Adam
2018-6-14
Well, I haven't examined your code that closely to understand why mPos is only length 12, but presumably you know what the x values should be for it. why is it 12 instead of 13? Is it shifted by 1 or is it the middle of the other samples? (I assume the former judging by the plot). whichever it is, just give an x vector that matches - e.g. x(1:end-1) or x(2:end) or x(1:end-1) + diff( x(1:2) ) / 2 or whatever is appropriate.
As an aside, don'y use square brackets here:
x = [-3:0.5:3];
You should get an M-lint warning in the code highlighting this. The [] is un-necessary as well as being less efficient, not that efficiency matters here, but it's good to get into more efficient habits when they cost nothing.
回答(2 个)
KSSV
2018-6-13
x = [0 30 60] ;
y = [0 0.3 0] ;
plot(x,y);
xi = x-30 ;
yi = y-0.3 ;
hold on
plot(xi,yi)
2 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Scatter Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!