Matrix Multiplication Error in MATLAB R2022 but Not in R2024 (ECEF-to-ECI Transformation)

1 次查看(过去 30 天)
I'm running a MATLAB script on macOS that performs sensor fusion using GNSS and IMU data. The script runs perfectly in MATLAB R2024 but fails in MATLAB R2022 with the following error during the ECEF to ECI frame transformation:
=== Task 5: ECI and ECEF Frame Plotting ===
Error using *
Incorrect dimensions for matrix multiplication. Check that the number of columns in the
first matrix matches the number of rows in the second matrix. To operate on each element
of the matrix individually, use TIMES (.*) for elementwise multiplication.
Error in untitled3>transform_ecef_to_eci_gnss (line 332)
pos_eci(i,:)= (Rz* pos_ecef(i,:).').';
Error in untitled3 (line 121)
transform_ecef_to_eci_gnss(T_gnss, EARTH_ROTATION_RATE);
I suspect there might be differences between MATLAB R2022 and R2024 that affect this function. I've confirmed that all required files and dependencies are present and that the MATLAB path is set correctly in both environments.
Below is the relevant portion of my code:
function Fusion_ECI_Corrected()
% FUSION_ECI_CORRECTED
% Enhanced GNSS and IMU Fusion in ECI Frame with Corrected Gravity Compensation and Drift Correction,
% using load_nav_data().
%% Task 0: Configuration
[IMU_Data, GNSS_Data, fsIMU, fsGNSS] = load_nav_data();
T_imu = struct2table(IMU_Data);
T_gnss = struct2table(GNSS_Data);
% Rename velocity fields if necessary
if ismember('Velocity_X', T_gnss.Properties.VariableNames)
T_gnss.Properties.VariableNames{'Velocity_X'} = 'VX_ECEF_mps';
end
if ismember('Velocity_Y', T_gnss.Properties.VariableNames)
T_gnss.Properties.VariableNames{'Velocity_Y'} = 'VY_ECEF_mps';
end
if ismember('Velocity_Z', T_gnss.Properties.VariableNames)
T_gnss.Properties.VariableNames{'Velocity_Z'} = 'VZ_ECEF_mps';
end
% Constants
EARTH_ROTATION_RATE = 7.2921159e-5;
% (Other constants and processing steps...)
%% Task 5: ECI and ECEF Transform & Plot
fprintf('\n=== Task 5: ECI and ECEF Transform & Plot ===\n');
[pos_eci_gnss, vel_eci_gnss, acc_eci_gnss, ...
pos_ecef_gnss, vel_ecef_gnss, acc_ecef_gnss] = transform_ecef_to_eci_gnss(T_gnss, EARTH_ROTATION_RATE);
% (Rest of the code for storing and plotting data)
end
function [pos_eci, vel_eci, acc_eci, pos_ecef, vel_ecef, acc_ecef] = transform_ecef_to_eci_gnss(T_gnss, EARTH_ROTATION_RATE)
t_rel = T_gnss.Posix_Time - T_gnss.Posix_Time(1);
theta = -EARTH_ROTATION_RATE .* t_rel;
cos_t = cos(theta);
sin_t = sin(theta);
pos_ecef = [T_gnss.X_ECEF_m, T_gnss.Y_ECEF_m, T_gnss.Z_ECEF_m];
vel_ecef = [T_gnss.VX_ECEF_mps, T_gnss.VY_ECEF_mps, T_gnss.VZ_ECEF_mps];
n = length(theta);
pos_eci = zeros(n, 3);
vel_eci = zeros(n, 3);
for i = 1:n
Rz = [cos_t(i), -sin_t(i), 0;
sin_t(i), cos_t(i), 0;
0, 0, 1];
pos_eci(i, :) = (Rz * pos_ecef(i, :)').';
vel_eci(i, :) = (Rz * vel_ecef(i, :)').';
end
dt = mean(diff(T_gnss.Posix_Time));
acc_eci = zeros(n, 3);
acc_ecef = zeros(n, 3);
for i = 2:n
acc_eci(i, :) = (vel_eci(i, :) - vel_eci(i-1, :)) / dt;
acc_ecef(i, :) = (vel_ecef(i, :) - vel_ecef(i-1, :)) / dt;
end
acc_eci(1, :) = acc_eci(2, :);
acc_ecef(1, :) = acc_ecef(2, :);
end
```
**What I've Tried:**
- Verified that all file paths and dependencies are correct in both MATLAB R2022 and R2024.
- Reviewed MATLAB’s documentation for any changes related to matrix multiplication or file I/O between versions.
**My Question:**
Has anyone encountered similar version-specific issues with matrix multiplication in MATLAB? Are there known changes between MATLAB R2022 and R2024 that could cause this error in the `transform_ecef_to_eci_gnss` function? How can I adjust my code to ensure compatibility with the older version?
**Additional Details:**
- **MATLAB R2024:** Works fine
- **MATLAB R2022:** Fails with the error above
- **OS:** macOS
  2 个评论
Matt J
Matt J 2025-3-27
编辑:Matt J 2025-3-27
It should be easy to troubleshoot. Just stop code execution at,
transform_ecef_to_eci_gnss (line 332)
and check the sizes of Rz and pos_ecf.
Cris LaPierre
Cris LaPierre 2025-3-27
编辑:Cris LaPierre 2025-3-27
Rz is defined as a 3x3 matrix and pos_ecf is an nx3 array extracted from a table and then transformed to a 3xn. So everything should be working if your provided data is what you expect.
If we could run your code, we might be able to help identify the issue. However, without it, you need to work backwards in your code to find why the data is not shaped as expected.

请先登录,再进行评论。

回答(0 个)

产品


版本

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by