interpolation for 2 numbers

조회 수: 1 (최근 30일)
sri satya ravi
sri satya ravi 2017년 1월 7일
답변: Star Strider 2017년 1월 7일
If i have an image something like this I want to know the 0.98th value of max power. That occurs on either side of the curve. How can I get the corresponding X-axis for 0.98*max_power.
max_power = 523.6947
  댓글 수: 2
Star Strider
Star Strider 2017년 1월 7일
I have no idea what you want.
Please put a ‘+’ or something on the curve that shows what you want to estimate. Also, it would help if you attach your data as a ‘.mat’ file so we can work with it.
sri satya ravi
sri satya ravi 2017년 1월 7일
Please look at the data...... I also attached a figure explaining what i wanted..I want to find the interpolated x values at the condition (0.98*max) indicated by 2 red marks in the figure.
Thanks

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

채택된 답변

Star Strider
Star Strider 2017년 1월 7일
Here you go:
The Code
D = load('sri satya ravi matlab.mat');
RPM = D.RPM;
Power = D.Power;
zci = @(v) find(v(:).*circshift(v(:), [-1 0]) <= 0); % Returns Approximate Zero-Crossing Indices Of Argument Vector
Pwr98Idx = zci(Power - 0.98*max(Power));
for k1 = 1:numel(Pwr98Idx)
RPMPwr98(k1) = interp1(Power(Pwr98Idx(k1)+(-1:1)), RPM(Pwr98Idx(k1)+(-1:1)), 0.98*max(Power), 'linear');
end
figure(1)
plot(RPM, Power)
hold on
plot(RPMPwr98, [1 1]*0.98*max(Power), 'rp', 'MarkerFaceColor','g')
hold off
grid
celtxt = regexp(sprintf('RPM = %.1f\n', RPMPwr98), '\n', 'split');
text(RPMPwr98, [1 1]*0.98*max(Power), celtxt(1:end-1), 'HorizontalAlignment','center', 'VerticalAlignment','bottom')
The Plot
The code is simple and straightforward, so I did not comment-document it. See the documentation on the individual functions for the details on how to use them.
The only special function is my ‘zci’ anonymous function. It detects zero crossings here by subtracting 98% of the maximum power from the power vector to create the zero-crossing indices, that are negative values in a vector (created by multiplying the vector by a 1-position shifted version of itself) that is otherwise positive. It then uses those indices to determine where to centre the interpolation, does the interpolation, and stores the results in the ‘RPMPwr98’ vector.
Experiment with the code and the function to see how it works.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Interpolation에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by