How to load the data file in Simulink using user define block?

clc;
clear all;
close all;
format long g;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 1) GNSS DATA PROCESSING
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% -------------------- File Reading --------------------
gnssFileName = 'GNSS_19.dat'; % Example GNSS data file (modify as needed)
try
% We assume 'GNSS_19.dat' has columns like:
% GPS_Week, Week_Time, RX_Pos_X, RX_Pos_Y, RX_Pos_Z, RX_Vel_X, RX_Vel_Y, RX_Vel_Z
GNSS_data = readtable(gnssFileName, 'Delimiter', ',', 'ReadVariableNames', true);
catch ME
error('Error reading GNSS file: %s', ME.message);
end
% -------------------- Basic Extraction -----------------
GNSS.GPS_Week = GNSS_data.GPS_Week;
GNSS.Week_Time = GNSS_data.Week_Time; % GNSS time reference
GNSS.RX_Pos_X = GNSS_data.RX_Pos_X;
GNSS.RX_Pos_Y = GNSS_data.RX_Pos_Y;
GNSS.RX_Pos_Z = GNSS_data.RX_Pos_Z;
GNSS.RX_Vel_X = GNSS_data.RX_Vel_X;
GNSS.RX_Vel_Y = GNSS_data.RX_Vel_Y;
GNSS.RX_Vel_Z = GNSS_data.RX_Vel_Z;
% -------------------- Compute Derived Quantities -------
% Velocity magnitude
GNSS.Vel_Magnitude = sqrt(GNSS.RX_Vel_X.^2 + GNSS.RX_Vel_Y.^2 + GNSS.RX_Vel_Z.^2);
% Heading in degrees (atan2d returns degrees)
GNSS.Heading_deg = atan2d(GNSS.RX_Vel_Y, GNSS.RX_Vel_X);
disp('GNSS data structure created successfully.');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 2) IMU DATA PROCESSING
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% -------------------- File Reading --------------------
imuFileName = 'IMU_19.dat'; % Example IMU data file (modify as needed)
fid = fopen(imuFileName, 'r');
if fid == -1
error('Cannot open the file "%s".', imuFileName);
end
try
% We assume 'IMU_19.dat' has 10 columns with 10,000 rows:
% Time, <unused>, AccX, AccY, AccZ, GyroX, GyroY, GyroZ, <unused>, <unused>
rawData = textscan(fid, '%f %f %f %f %f %f %f %f %f %f', ...
'Delimiter', {' ', '\t'}, 'MultipleDelimsAsOne', true);
fclose(fid);
catch ME
fclose(fid);
error('Error reading IMU file: %s', ME.message);
end
IMU_data = cell2mat(rawData);
[numRows, numCols] = size(IMU_data);
if (numRows ~= 10000 || numCols ~= 10)
error('Unexpected IMU data dimensions: %d rows x %d cols (expected 10000 x 10)', ...
numRows, numCols);
end
% -------------------- Basic Extraction -----------------
IMU.Time = IMU_data(:, 1); % 1) Time
IMU.Acc_X = IMU_data(:, 3); % 3) Acc X
IMU.Acc_Y = IMU_data(:, 4); % 4) Acc Y
IMU.Acc_Z = IMU_data(:, 5); % 5) Acc Z
IMU.Gyro_X = IMU_data(:, 6); % 6) Gyro X
IMU.Gyro_Y = IMU_data(:, 7); % 7) Gyro Y
IMU.Gyro_Z = IMU_data(:, 8); % 8) Gyro Z
disp('IMU data structure created successfully.');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 3) OPTIONAL PSEUDORANGE/TDCP DATA HANDLING
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% If you have another file containing pseudorange & TDCP data, read them here:
%
% pseudoFileName = 'pseudorange_data.dat';
% tdcpFileName = 'tdcp_data.dat';
% [Pseudo, TDCP] = read_pseudorange_tdcp(pseudoFileName, tdcpFileName);
%
% For now, we assume you have placeholders or do not need them in the final code.
% Make sure any arrays from these sources get interpolated to match IMU.Time if needed.
I have made matlab script but how to load the data in simulink using user define block?

Answers (1)

Vims
Vims on 28 Dec 2024
Moved: Walter Roberson on 28 Dec 2024
Here is the solution
read the read_me_file and you will come to know how to load the data in simulink using user define block. Thanks

Products

Release

R2024a

Asked:

on 27 Dec 2024

Moved:

on 28 Dec 2024

Community Treasure Hunt

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

Start Hunting!