MATLAB Answers


how to make 2d lookup table when having 3 vectors

Asked by manoj saladi on 9 Apr 2019
Latest activity Commented on by manoj saladi on 9 Apr 2019
Accepted Answer by KSSV
I have 3 vectors each of order 1xn.
namely torque, flux and current. So, depending on the torque and the flux value I need the current as output. I want to use 2d Lookup table for this, but the table data should be nxn. That means my current matrix should be nxn, but my current matrix is actually 1xn. So, is there any way to convert this current vector into matrix, is it possible?


Sign in to comment.

2 Answers

Answer by KSSV
on 9 Apr 2019
 Accepted Answer

Let t,f,c be your torque, flux and current vectors respectively.
F = scatteredInterpolant(t,f,c) ;
ci = F(ti,fi)


Show 1 older comment
Let t,f,c be your torque, flux and current vectors respectively.
n = 100 ;
ti = linspace(min(t),max(t),N) ;
fi = linspace(min(f),max(f),N) ;
[T,F] = meshgrid(ti,fi) ;
C = griddata(t,f,c,T,F) ;
Or depending ont he data, it mght be possible with reshaping t,f andc.
Thank you I will try this. but I have a doubt since the relationhip between torque and flux is not linear, it some what looks like in the picture. So, I feel this might create problems.matlab question.PNG
It is a you can get it into matrix? My first answer is the option for you.

Sign in to comment.

Answer by John D'Errico
on 9 Apr 2019

The problem is, your data is insufficient to create a 2-d surface from only that data. (Yes, you CAN use a scatteredInterpolant, but the reult will be very poor.) This is also why I told you in your last question that gridfit is not a good tool to solve the problem.
So why can you not use data like that to form a complete surface, a 2-d lookup table? It lives in only a very small region of the space, almost entirely along one curve, much of that being virtually a straight line. And replicating the data, as you seem to have wanted to do in your last question does not give you more useful information.
You talk about the relationship between torque and flux not being linear. But if they are to be used to populate a 2-d lookup table, you don't want any relationship at all to exist between the DEPENDENT variables of your table. So, why is that type of data not good to populate a 2-d table?
You have never been willing to show me your data, even though I have asked. But here is an example of a similar case, where a similar amount of information exists.
x = linspace(0,1,10);
y = sin(1.5*x);
grid on
So, we have some highly dependent variables, x and y. Now suppose we want to create a 2-d lookup table, where some other variable z happens to be a function of x and y. So imagine that you have measured z at each of those points, This is the case you have described. where you have current as a function of flux and torque.
But your data lies only along that narrow band in the (x,y) plane. At any point away from that narrow band, you have no information at what the shape of that surface might be. This will cause gridfit to perform miserably. It will cause a scattered interpolant to fail in flames.
What happens with a scattered interpolant?
tri = delaunay(x,y)
hold on
The dots wer your data. The triangular mesh is what a scattered interpolant will use to interpolant. At any point, it determines which of those triangles the point lies inside, then uses the z values at the 3 corner vertices of the corresponding triangle to do interpolation. See that EVERY triangle here connects a line segment to the point at the very end.
The goal of a scattered interpolant is to use data that is NEAR a point in question to interpolate. But in a problem like this, that fails miserably. Where are scattered interpolants good? Or, for that matter, where are tools like gridfit good?
A classical problem where scatteredInterpolant is a good tool might be:
x = rand(100,1);
y = rand(100,1);
tri = delaunay(x,y);
hold on
grid on
Here, at any point in the (x,y) plane, the tool uses those data points that surround any point in question to interpolate the value of z. Even there, extrapolating into the curners becomes a problem (a case where gridfit is designed to operate a little more robustly than a scattered interpolant.) But we don't have a very narrow band of data, so at least within the domain that contains our data, any tool will do reasonably well.
The issue is, you don't seem to have that kind of data. And again, replicating your data does not give you more data. It can just give you more bad data.

  1 Comment

Thank you very much for a detailed explanation. The problem with my data is, eventough the current is dependent on torque and flux values there is no equation relationship between them. In more detail in table data I know currents only on the diagonal of the matrix, where torque and flux are break points. So I want to find current values for every combination of torque and flux values which gives all off diagonal elements in the current matrix.
I don't know if gridfit is suitable for it or not? But I would like to know if there is a way to do it.
Thank you.

Sign in to comment.