Interpolation using two variables

Hi,
I have two variables accelerator pedal and vehicle speed and corresponding value for Z.
I want a solution which will give me Z value if i give any random acc pedal and vehicle speed value.
Max value of Z can be 10, not more than that.
Thanks

Antworten (3)

Rik
Rik am 24 Jul. 2020

0 Stimmen

doc interp2

4 Kommentare

Sanket Gaikwad
Sanket Gaikwad am 26 Jul. 2020
I've seen the interp2 function before asking here but couldn't understand it. That's why I'm asking here.
Rik
Rik am 26 Jul. 2020
What did you try? Did you follow any of the examples in the documentation? What errors did you get?
Sanket Gaikwad
Sanket Gaikwad am 26 Jul. 2020
I didn't get any errors. In the documentation they are using meshgrid function. That's the part that I didn't understand. I don't know how to convert my data similar to what they are using for interp2 functions input. Also my data has different interval for acc pedal and vehicle speed, I don't know how to include this information in interp2.
Rik
Rik am 26 Jul. 2020
You have 2 vectors that determine the x and y values. What code did you try with meshgrid?

Melden Sie sich an, um zu kommentieren.

Image Analyst
Image Analyst am 26 Jul. 2020
Bearbeitet: Image Analyst am 26 Jul. 2020

0 Stimmen

Here is a demo for scatteredInterpolant. But if you can't understand interp2() you probably won't understand this either.
Give us code to create your table if you need more help. Make it easy for us to help you, not hard.
Image Analyst
Image Analyst am 26 Jul. 2020

0 Stimmen

Sanket, try this demo of interp2(). Adapt as needed, like using your own matrix instead of my "myMatrix".
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format short g;
format compact;
fontSize = 18;
fprintf('Beginning to run %s.m ...\n', mfilename);
% Create a sample matrix using the MATLAB peaks logo function.
myMatrix = peaks(11)
% Scale it so that it's in the range 0-10.
myMatrix = rescale(myMatrix, 0, 10)
% Plot it as a surface so we can visualize it.
surf(myMatrix)
% Add axes labels.
xlabel('Vehicle Speed', 'FontSize', fontSize);
ylabel('Acc Pedal', 'FontSize', fontSize);
zlabel('Z', 'FontSize', fontSize);
% Find out what the value is at x=6.5 and y=7.5
xq = 6.5;
yq = 7.5;
z = interp2(myMatrix, xq, yq)
% Plot that point on the surface as a red dot.
hold on;
plot3(xq, yq, z, 'r.', 'MarkerSize', 30);
caption = sprintf('Z = %.2f at (%.1f, %.1f)', z, xq, yq);
title(caption, 'FontSize', fontSize);
fprintf('Doe running %s.m ...\n', mfilename);

Kategorien

Mehr zu Graphics Object Properties finden Sie in Hilfe-Center und File Exchange

Produkte

Version

R2015b

Gefragt:

am 24 Jul. 2020

Beantwortet:

am 26 Jul. 2020

Community Treasure Hunt

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

Start Hunting!

Translated by