How to populate 2D array from 2 vectors perpendicular to each other?

I have 2 files. Each file contains 4 columns. Column 1, 2 and 3 define the location of a point in x, y, and z-axis respectively, on a Cartesan coordinate. Column 4 is the Value of that point. 'Inline' and 'Crossline' are perpendicular to each other and intersect at (0,0) coordinate. How do I populate a 2D array from these 2 files? (The data below are simplified. The real data has finer resolution)
Inline =
2.800000 0 15.0000 1.3678
1.000000 0 15.0000 1.2000
0 0 15.0000 1.0000
-1.000000 0 15.0000 1.2000
-2.500000 0 15.0000 1.5688
Crossline =
0 -2.300000 15.0000 1.3546
0 -1.000000 15.0000 1.1000
0 0 15.0000 1.0000
0 1.000000 15.0000 1.1500
0 2.700000 15.0000 1.3558

7 Comments

Populate it based on what rule?
  1. Inline data will be the main data to be duplicated.
  2. Data to be duplicated for each Y-axis point available on Crossline
  3. Duplicated 'Value' in column 4 should be scaled such that any original 'Value' from the 2 files remain the same
Show the expected output given the simplified example data you gave above.
The sample matrices do not represent vectors.
Expected output =
2.800000 -2.300000 15.0000 1.3678*1.3546
1.000000 -2.300000 15.0000 1.2000*1.3546
0 -2.300000 15.0000 1.3546
-1.000000 -2.300000 15.0000 1.2000*1.3546
-2.500000 -2.300000 15.0000 1.5688*1.3546
2.800000 -1.000000 15.0000 1.3678*1.1000
1.000000 -1.000000 15.0000 1.2000*1.1000
0 -1.000000 15.0000 1.1000
-1.000000 -1.000000 15.0000 1.2000*1.1000
-2.500000 -1.000000 15.0000 1.5688*1.1000
2.800000 0 15.0000 1.3678
1.000000 0 15.0000 1.2000
0 0 15.0000 1.0000
-1.000000 0 15.0000 1.2000
-2.500000 0 15.0000 1.5688
2.800000 1.000000 15.0000 1.3678*1.1500
1.000000 1.000000 15.0000 1.2000*1.1500
0 1.000000 15.0000 1.1500
-1.000000 1.000000 15.0000 1.2000*1.1500
-2.500000 1.000000 15.0000 1.5688*1.1500
2.800000 2.700000 15.0000 1.3678*1.3558
1.000000 2.700000 15.0000 1.2000*1.3558
0 2.700000 15.0000 1.3558
-1.000000 2.700000 15.0000 1.2000*1.3558
-2.500000 2.700000 15.0000 1.5688*1.3558
Each of those groups is "V-shaped"; the inputs are not "two vectors perpendicular to each other".
OK. So is it possible to get this sort of expected results?

Sign in to comment.

 Accepted Answer

This is my attempt to generalize your description. Let (x0,y0,z0) be the point of intersection of your two lines. (Note: The lines you gave intersected at (0,0,15).) I have abbreviated the names of the lines as 'I' and 'C'.
[XI,XC] = ndgrid(I(:,1),C(:,1));
[YI,YC] = ndgrid(I(:,2),C(:,2));
[ZI,ZC] = ndgrid(I(:,3),C(:,3));
[VI,VC] = ndgrid(I(:,4),C(:,4));
OUT = [XI(:)+XC(:)-x0,YI(:)+YC(:)-y0),ZI(:)+ZC(:)-z0,VI(:).*VC(:)];
I depended entirely on your stated expected output, since I could not understand your verbal description of it at all. I gather you want to complete the "grid" consisting of all possible pairing of points on the two lines and at each grid point you want the value to be the product of the corresponding values given by the two lines.
Roger Stafford

3 Comments

Unfortunately the input does not actually form vectors; A(:,4) and B(:,4) are both V-shaped.
I went for the math approach first, and then when cross-checking found it was not suitable.
The scheme Yun Inn used was to replicate each (X,Y) combination, with the new 4th column being the product of the respective 4th columns.
The way I see it, the first three columns of "inline" and "crossline" do each constitute points along straight lines. These are in fact parallel to the x and y axes, respectively. In the output the x, y, z points are located in a rectangular gridwork based on intersections of lines which run through the points along each line and are parallel to the two respective lines. At least that is the way that seemed most likely. The explanation given was certainly not helpful.
Roger's description is exactly what I wanted to achieve. Apology for my poor explanation.
Thank you for all the inputs. The solution works!

Sign in to comment.

More Answers (1)

[a,b] = ndgrid(A(:,1), B(:,2));
c = bsxfun(@times, A(:,4), B(:,4).');
Output = [a(:), b(:), A(:,3)*ones(size(A,1)*size(B,1),1), c(:)];

1 Comment

[a,b,c] = ndgrid(A(:,1), B(:,2), A(:,3));
d = A(:,4)*(B(:,4).');
Output = [a(:), b(:), c(:), d(:)];

Sign in to comment.

Categories

Find more on Function Creation in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!