interpolation of scatter data

2 vues (au cours des 30 derniers jours)
Solmaz Kahourzade
Solmaz Kahourzade le 4 Mai 2018
Commenté : Star Strider le 4 Mai 2018
Hi, I am new in Matlab and I have difficulty in solving this problem. I have a matrix as bellow where Fd is a function of Id and Iq and also Fq is a function of Id and Iq. I want to extend my results for a 128*128 matrix of Id and Iq. The code that I used is as:
Id_vector = linspace(-200,0,128);
Iq_vector = linspace(-200,0,128);
[ Id , Iq ] = meshgrid(Id_vector,Iq_vector);
but I can not create a function for Fd and Fq using two variables. I tried the interp1 and ppval without any success. would you please help me?
Id Iq Fd Fq
0 0 0.001 -0.172
-50.0 0 0.001 -0.186
-100 0 0.001 -0.196
-150 0 0.001 -0.204
-200 0 0.001 -0.210
0 -50 -0.020 -0.172
-50 -50 -0.019 -0.186
-100 -50 -0.017 -0.196
-150 -50 -0.016 -0.204
-200 -50 -0.015 -0.210
0.0 -100.0 -0.042 -0.171
-50.0 -100.0 -0.039 -0.185
-100.0 -100.0 -0.036 -0.195
-150.0 -100.0 -0.034 -0.203
-200.0 -100.0 -0.032 -0.209
0.0 -150.0 -0.064 -0.168
-50.0 -150.0 -0.060 -0.182
-100.0 -150.0 -0.056 -0.192
-150.0 -150.0 -0.052 -0.200
-200.0 -150.0 -0.049 -0.206
0.0 -200.0 -0.085 -0.164
-50.0 -200.0 -0.079 -0.178
-100.0 -200.0 -0.074 -0.188
-150.0 -200.0 -0.069 -0.196
-200.0 -200.0 -0.065 -0.203

Réponse acceptée

Star Strider
Star Strider le 4 Mai 2018
Your data are gridded, so you simply need to reshape the vectors to create matrices:
% Id Iq Fd Fq
M = [ 0 0 0.001 -0.172
-50.0 0 0.001 -0.186
-100 0 0.001 -0.196
-150 0 0.001 -0.204
-200 0 0.001 -0.210
0 -50 -0.020 -0.172
-50 -50 -0.019 -0.186
-100 -50 -0.017 -0.196
-150 -50 -0.016 -0.204
-200 -50 -0.015 -0.210
0.0 -100.0 -0.042 -0.171
-50.0 -100.0 -0.039 -0.185
-100.0 -100.0 -0.036 -0.195
-150.0 -100.0 -0.034 -0.203
-200.0 -100.0 -0.032 -0.209
0.0 -150.0 -0.064 -0.168
-50.0 -150.0 -0.060 -0.182
-100.0 -150.0 -0.056 -0.192
-150.0 -150.0 -0.052 -0.200
-200.0 -150.0 -0.049 -0.206
0.0 -200.0 -0.085 -0.164
-50.0 -200.0 -0.079 -0.178
-100.0 -200.0 -0.074 -0.188
-150.0 -200.0 -0.069 -0.196
-200.0 -200.0 -0.065 -0.203];
IdMtx = reshape(M(:,1), 5, []);
IqMtx = reshape(M(:,2), 5, []);
FdMtx = reshape(M(:,3), 5, []);
FqMtx = reshape(M(:,4), 5, []);
figure(1)
surf(IdMtx, IqMtx, FdMtx)
grid on
xlabel('Id')
ylabel('Iq')
zlabel('Fd')
figure(2)
surf(IdMtx, IqMtx, FqMtx)
grid on
xlabel('Id')
ylabel('Iq')
zlabel('Fq')
Use the griddata (link) function to interpolate to a finer mesh. I would not extrapolate beyond the limits of your data, because you have no idea what your data are outside those limits.
IdIq = linspace(min(IdMtx(:)), max(IdMtx(:)), 250); % Create Interpolation Vector (250 elements)
[Idi,Iqi] = meshgrid(IdIq); % Create Interpolation Matrices
Fdi = griddata(IdMtx, IqMtx, FdMtx, Idi, Iqi); % Interpolate ‘Fd’
Fqi = griddata(IdMtx, IqMtx, FqMtx, Idi, Iqi); % Interpolate ‘Fq’
figure(3)
mesh(Idi, Iqi, Fdi)
grid on
xlabel('Id')
ylabel('Iq')
zlabel('Fd')
figure(4)
mesh(Idi, Iqi, Fqi)
grid on
xlabel('Id')
ylabel('Iq')
zlabel('Fq')
I use the default 'linear' interpolation method here, because it seems appropriate to these surfaces.
Experiment to get the result you want.
  2 commentaires
Solmaz Kahourzade
Solmaz Kahourzade le 4 Mai 2018
Dear Star Strider,
Thank you so much. It is exactly what I needed.
Star Strider
Star Strider le 4 Mai 2018
My pleasure.
If my Answer helped you solve your problem, please Accept it!

Connectez-vous pour commenter.

Plus de réponses (1)

KSSV
KSSV le 4 Mai 2018
A = [0 0 0.001 -0.172
-50.0 0 0.001 -0.186
-100 0 0.001 -0.196
-150 0 0.001 -0.204
-200 0 0.001 -0.210
0 -50 -0.020 -0.172
-50 -50 -0.019 -0.186
-100 -50 -0.017 -0.196
-150 -50 -0.016 -0.204
-200 -50 -0.015 -0.210
0.0 -100.0 -0.042 -0.171
-50.0 -100.0 -0.039 -0.185
-100.0 -100.0 -0.036 -0.195
-150.0 -100.0 -0.034 -0.203
-200.0 -100.0 -0.032 -0.209
0.0 -150.0 -0.064 -0.168
-50.0 -150.0 -0.060 -0.182
-100.0 -150.0 -0.056 -0.192
-150.0 -150.0 -0.052 -0.200
-200.0 -150.0 -0.049 -0.206
0.0 -200.0 -0.085 -0.164
-50.0 -200.0 -0.079 -0.178
-100.0 -200.0 -0.074 -0.188
-150.0 -200.0 -0.069 -0.196
-200.0 -200.0 -0.065 -0.203] ;
Id = A(:,1) ; Iq = A(:,2) ; Fd = A(:,3) ;Fq = A(:,4) ;
% Do interpolation
Id_vector = linspace(-200,0,128);
Iq_vector = linspace(-200,0,128);
[ Idi , Iqi ] = meshgrid(Id_vector,Iq_vector);
F1 = scatteredInterpolant(Id,Iq,Fd) ;
Fdi = F1(Idi,Iqi) ;
F2 = scatteredInterpolant(Id,Iq,Fq) ;
Fqi = F2(Idi,Iqi) ;

Catégories

En savoir plus sur Interpolation dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by