mtex icon indicating copy to clipboard operation
mtex copied to clipboard

Inconsistent behavior in vector3d constructor?

Open gsparks3 opened this issue 9 months ago • 1 comments

I noticed some inconsistent behavior in the vector3d constructor. I was considering trying to fix it myself, but I wanted to make sure that I didn't introduce any new bugs in the process ... pondering fixes, I think the case of a 3x3 input matrix might be an issue, since you can't unambiguously define whether the output should be a row or column vector solely from the shape of the input, unlike other N x 3 or 3 x N matrices.

Example of inconsistent behavior:

% Create some row vectors
x = rand(1, 10);
y = rand(1, 10);
z = rand(1, 10);

% Create a vector3d from row vectors - result is a row vector (reasonable)
vector3d(x, y, z)

ans = vector3d
 size: 1 x 10
[...]

% Create a vector3d from column vectors - result is a column vector (reasonable)
vector3d(x', y', z')
 
ans = vector3d
 size: 10 x 1
[...]

% Create a 3 x N matrix
xyz = [x; y; z;];

% Create a vector3d from 3 x N matrix - result is a 1 x N vector3d (reasonable)
vector3d(xyz)
 
ans = vector3d
 size: 1 x 10
[...]

% Create a vector3d from N x 3 matrix - unexpected result!
vector3d(xyz')
 
ans = vector3d
 size: 1 x 3
[...]

Expected result: If a 3 x N matrix produces a 1 x N vector3d, a N x 3 matrix should produce a N x 1 vector3d. However, a 3 x 3 matrix is ambiguous. Possibly best to have that case throw a warning or error.

What MTEX version do you use? MTEX 5.11.2

gsparks3 avatar May 27 '24 19:05 gsparks3