フィルターのクリア

how to shift position of an index of max value to origo in matlab?

6 ビュー (過去 30 日間)
kat001
kat001 2018 年 6 月 13 日
編集済み: kat001 2018 年 6 月 14 日
Hi, I would like to shift the position the maximum value so that the maximum value is at the center, i.e. at origo.
  7 件のコメント
kat001
kat001 2018 年 6 月 14 日
編集済み: kat001 2018 年 6 月 14 日
Ok. But exactly how am I gonna do that? Because x has already the length of 13. It is 'mPos' is has a length of 12. How can I get the same vector lengths?
Adam
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
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 件のコメント
kat001
kat001 2018 年 6 月 13 日
Thank you. Now, imagine that x axis is not only bound to 0 to 60, instead it could be any length. How would I be able to feed that into the code in such case?
KSSV
KSSV 2018 年 6 月 13 日
Let x, y be you data..
[val,idx]=max(y);
xi=x-x(idx);
yi=y-y(idx);

サインインしてコメントする。


kat001
kat001 2018 年 6 月 14 日
編集済み: kat001 2018 年 6 月 14 日
Now, currently the plot looks like this:
where the red line represents an position vector as the power is increasing. What I would like to do is following (used MS paint for visualization) :
In other words, as the Gaussian profile reaches its maximum, the only way to keep maximum power all time by holding the position at the same place. And I am stuck with the coding here.
So far, my code looks like this:
x = -3:0.1:3;
norm = normpdf(x,0,1);
m = 0;
mPos = zeros(length(norm),1);
for i = 2:length(norm)
if(norm(i)>norm(i-1))
m = m + 0.1;
else
m = m - 0.1;
end
mPos(i) = m;
end
plot(x, mPos, 'r')
hold on
plot(x, norm, 'b')
grid on
hold off

カテゴリ

Help Center および File ExchangeScatter Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by