How to map a matrix based on values from another matrix
Show older comments
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
Walter Roberson
on 28 Jun 2020
Suppose A(i, j) = -2.6, then what would you want C(A(i, j), j) to mean?
Kashif
on 28 Jun 2020
madhan ravi
on 28 Jun 2020
Did you even look the answer below??
Walter Roberson
on 28 Jun 2020
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?
Answers (1)
madhan ravi
on 28 Jun 2020
Edited: madhan ravi
on 28 Jun 2020
0 votes
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
Kashif
on 28 Jun 2020
Kashif
on 28 Jun 2020
Walter Roberson
on 28 Jun 2020
I do not understand how sort could possibly help here.
Kashif
on 28 Jun 2020
Walter Roberson
on 28 Jun 2020
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.
Kashif
on 28 Jun 2020
Walter Roberson
on 29 Jun 2020
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.
Supriya Gain
on 19 Apr 2023
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!
Categories
Find more on Resizing and Reshaping Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!