Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inconsistent behavior in vector3d constructor? #2145

Open
gsparks3 opened this issue May 27, 2024 · 1 comment
Open

Inconsistent behavior in vector3d constructor? #2145

gsparks3 opened this issue May 27, 2024 · 1 comment

Comments

@gsparks3
Copy link
Contributor

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

@ralfHielscher
Copy link
Member

Hi,

I agree that the behavior is not desirable. Unfortunately, I also do not oversee whether changing this behavior creates unintended bugs. As a workaround I would recommend to use vector3d.byXYZ(d)' whenever you have a Nx3 data matrix and vector3d(d)` whenever you have a 3xN data matrix.

Ralf.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants