how to solve "error using griddata" in order to plot an efficiency map

hello i'm trying to plot an efficiency map of a motor using vectors of torque and speed and their corresponding efficiencies obtained from some measurments is it possible to plot efficiency map with this?
ps: the vectors are loaded from an excel file
I'm trying to plot somthing similar with this script
x0=min(speedRPM); x1=max(speedRPM); nx=100;
y0=min(TorqueNm); y1=max(TorqueNm); ny=100;
x=linspace(x0,x1,nx);
y=linspace(y0,y1,ny);
[X,Y]=meshgrid(x,y);
Z=griddata(speedRPM,TorqueNm,EffeciencyPer,X,Y);
contourf(X,Y,Z);
colorbar;
But when i run it it shows me this error
>> efficiencymap
Error using griddata (line 110)
X and Y must be same length as Z or the lengths of X and Y must match the size of Z.
could you help ?

2 comentarios

DGM
DGM el 11 de Mayo de 2021
Editada: DGM el 11 de Mayo de 2021
The error message says there's a problem with the size or orientation of arrays, but nobody can know how your arrays are sized or oriented unless you tell us.
% test arrays have corresponding size
speedRPM = 1:200; % 1x200
TorqueNm = 1:100; % 1x100
EffeciencyPer = speedRPM + TorqueNm'; % 100x200
% all this code runs just fine with test arrays
x0=min(speedRPM); x1=max(speedRPM); nx=100;
y0=min(TorqueNm); y1=max(TorqueNm); ny=100;
x=linspace(x0,x1,nx);
y=linspace(y0,y1,ny);
[X,Y]=meshgrid(x,y);
Z=griddata(speedRPM,TorqueNm,EffeciencyPer,X,Y);
contourf(X,Y,Z);
colorbar;
HI i'm atteching the excel files here could you check them please ?

Iniciar sesión para comentar.

Respuestas (1)

Walter Roberson
Walter Roberson el 11 de Mayo de 2021
Editada: Walter Roberson el 11 de Mayo de 2021
% test arrays have corresponding size
speedRPM = 1:200; % 1x200
TorqueNm = 1:100; % 1x100
EffeciencyPer = speedRPM + TorqueNm'; % 100x200
% all this code runs just fine with test arrays
x0=min(speedRPM); x1=max(speedRPM); nx=100;
y0=min(TorqueNm); y1=max(TorqueNm); ny=100;
x=linspace(x0,x1,nx);
y=linspace(y0,y1,ny);
[X,Y] = meshgrid(x,y);
F = scatteredInterpolant(speedRPM, TorqueNm, EfficiencyPer);
Z = F(X, Y);
contourf(X, Y, Z.'); %probably Z.', perhaps Z instead

4 comentarios

To be honest, I don't know what to make of these curves. (Z.' on left)
speedRPM = readmatrix('https://www.mathworks.com/matlabcentral/answers/uploaded_files/615045/speedRPM.xlsx');
TorqueNm = readmatrix('https://www.mathworks.com/matlabcentral/answers/uploaded_files/615040/TorqueNm.xlsx');
EffeciencyPer = readmatrix('https://www.mathworks.com/matlabcentral/answers/uploaded_files/615035/EffeciencyPer.xlsx');
x0 = min(speedRPM); x1=max(speedRPM); nx=100;
y0 = min(TorqueNm); y1=max(TorqueNm); ny=101;
x = linspace(x0,x1,nx);
y = linspace(y0,y1,ny);
[X,Y] = meshgrid(x,y);
F = scatteredInterpolant(speedRPM, TorqueNm, EffeciencyPer);
Z = F(X, Y);
contourf(X, Y, Z); %probably Z.', perhaps Z instead
figure();
plot3(speedRPM, TorqueNm, EffeciencyPer)
xlabel('speed')
ylabel('torque')
zlabel('efficiency')
The data is not really representative enough to establish a contour.
thank you so much !
but could you explain how you solved this issue please just in case i get new arrays for new measurments how to determine their sizes in order to avoid this error repeating
You do not need to determine their size. nx and ny are arbitrary; the higher they are, the smoother the plot will be, but the longer it will take to compute.

Iniciar sesión para comentar.

Categorías

Preguntada:

el 11 de Mayo de 2021

Comentada:

el 12 de Mayo de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by