How to map a matrix based on values from another matrix

Hi,
I have two matrices A (mxn) and B (mxn). I want to make another matrix C (mn xn).
I want to pick a data point from B (i, j) and place in C such that
C (A (i, j), j) = B (i, j)
The issue is A (i, j) can be negative and / or floating.
Is it possible?

4 Comments

Suppose A(i, j) = -2.6, then what would you want C(A(i, j), j) to mean?
yes, this is the issue. So I wanted to know is there another way to do the same.
Did you even look the answer below??
What would you want C(-2.6,j) to mean if one of the A values was -2.6?
Are you trying to do scattered interpolation?

Sign in to comment.

Answers (1)

madhan ravi
madhan ravi on 28 Jun 2020
Edited: madhan ravi on 28 Jun 2020
You could sort(...) and use it’s second output to index (which satisfies the data points needed under needed tolerance) to get what you want, you will have to experiment as per your needs.

8 Comments

Hi, yes. I read documentation for sort as i never used it before. I am not a frequent user of MATLAB and other programming languages. I couldn't get how i can use this sort function. I am trying witn it. lets see.
A(i,j) vary from -90 to 54.56 also can be same at multiple points. The distribution of A(i,j) is random and values also repeat.
I do not understand how sort could possibly help here.
btw, i was able to see a data map as C (A (i, j), j) = B (i, j) by surf function.
surf(n1:end, A, B); view(2); shading interp
where n1:end is a row vector
By this line, I was able to see a data map as C (A (i, j), j) = B (i, j)
I dn't know how surf did it as its documentation does not mention anything like this.
Now when i tried to extract ZData from s = surf(n1:end, A, B); z = s.ZData;
it gave me data in matrix B. So it is possible to see data as C but i could not save it for further use.
I even saved it as *.fig file and then extracted ZData but again it gave me data in B.
Any ideas?
It appears to me that at particular y values (which you have stored in A) that you want the height to be what you have stored in B, and that at other locations where you do not happen to have recorded data, that you want the height to be influenced by what is known.
Is that correct?
Because if it is, then you should be doing scattered interpolation.
A and B have same diemesions so for each data point in B there is a crossponding value in A. So, I think interpolation is not needed.
Or may be surf also uses some interpolation as it shows you data as a continuous map? and not a wire grid like mesh...
Even a wire grid has interpolation. Lack of interpolation would be like a scatter3() graph, where you just have a bunch of unconnected points, where there exist some locations in which there is an infinitesimally small post that the point sits on, and that between the posts there is either "nonethingness" (nan) or -infinity, with there being no implicit connection between nearby points at all.
surface and wire meshes assume connections between nearby points and draw lines and faces between them, sort of like draping a piece of fabric over the set of points. That is implied interpolation. If you are wanting a surface out, then you should be doing scattered interpolation.
The fact that the two arrays are the same size does not affect whether you should be doing scattered interpolation, because the size of the surface implied by the points is not the same as the number of data points. You want to know the shape of the surface over some bounds, effectively sampling it on a regular grid within the bounds and asking what the height is at each of the sample points.
I have a matrix A=[1 2;1 3;1 9] and I have another matrix B which is 203x3. Now I want to map A matrix to B. Like first row to A matrix should be map to first column of B matrix. How to do that!

Sign in to comment.

Categories

Asked:

on 27 Jun 2020

Commented:

on 19 Apr 2023

Community Treasure Hunt

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

Start Hunting!