Simplifying a TDMS reading code
I am trying to read multiple groups and channels of a TDMS file and doing some graphing and calculations at the end. I need to be able to acceses any channel or group that I want to use in the graphs or calcualtions, I would really apperciate it if someone had any advice on sliming the code down it currently takes 6 mins to run which is a really long time.
defaultFolder = ‘C:UserslillypColostateLute,Chris – EM-TRAS internalMatlab’;
addpath(defaultFolder);
fileFilter = ‘*.tdms’;
[fileName, filepath] = uigetfile(fullfile(defaultFolder, fileFilter), ‘Select a TDMS file’);
if fileName ~= 0
fullFilePath = fullfile(filepath, fileName);
disp([‘Selected file: ‘, fullFilePath]);
else
disp(‘No file selected.’);
end
fileName = fullFilePath;
group_Time = "Torques";
channel_Time = "Timestamp";
tdmsreadprop(fileName, "ChannelGroupName",group_Time, "ChannelName", channel_Time);
data = tdmsread(fileName, "ChannelGroupName",group_Time, "ChannelName", channel_Time);
time = data{1};
if istable(time)
time = table2array(time);
elseif isdatetime(time)
time = seconds(time – time(1));
end
% Speed readings%
group_N1 = "Rotary encoders";
channel_N1 = "N1 [RPM]";
tdmsreadprop(fileName, "ChannelGroupName",group_N1, "ChannelName", channel_N1);
data = tdmsread(fileName, "ChannelGroupName",group_N1, "ChannelName", channel_N1);
N1 = data{1};
group_N2 = "Rotary encoders";
channel_N2 = "N2 [RPM]";
tdmsreadprop(fileName, "ChannelGroupName",group_N2, "ChannelName", channel_N2);
data = tdmsread(fileName, "ChannelGroupName",group_N2, "ChannelName", channel_N2);
N2 = data{1};
group_N3 = "Rotary encoders";
channel_N3 = "N3 [RPM]";
tdmsreadprop(fileName, "ChannelGroupName",group_N3, "ChannelName", channel_N3);
data = tdmsread(fileName, "ChannelGroupName",group_N3, "ChannelName", channel_N3);
N3 = data{1};
group_N4 = "Rotary encoders";
channel_N4 = "N4 [RPM]";
tdmsreadprop(fileName, "ChannelGroupName",group_N4, "ChannelName", channel_N4);
data = tdmsread(fileName, "ChannelGroupName",group_N4, "ChannelName", channel_N4);
N4 = data{1};
group_N5 = "Rotary encoders";
channel_N5 = "N5 [RPM]";
tdmsreadprop(fileName, "ChannelGroupName",group_N5, "ChannelName", channel_N5);
data = tdmsread(fileName, "ChannelGroupName",group_N5, "ChannelName", channel_N5);
N5 = data{1};
group_N6 = "Rotary encoders";
channel_N6 = "N6 [RPM]";
tdmsreadprop(fileName, "ChannelGroupName",group_N6, "ChannelName", channel_N6);
data = tdmsread(fileName, "ChannelGroupName",group_N6, "ChannelName", channel_N6);
N6 = data{1};
group_N7 = "Rotary encoders";
channel_N7 = "N7 [RPM]";
tdmsreadprop(fileName, "ChannelGroupName",group_N7, "ChannelName", channel_N7);
data = tdmsread(fileName, "ChannelGroupName",group_N7, "ChannelName", channel_N7);
N7 = data{1};
group_N8 = "Rotary encoders";
channel_N8 = "N8 [RPM]";
tdmsreadprop(fileName, "ChannelGroupName",group_N8, "ChannelName", channel_N8);
data = tdmsread(fileName, "ChannelGroupName",group_N8, "ChannelName", channel_N8);
N8 = data{1};
% Torque readings%
group_T1 = "Torques";
channel_T1 = "T1 [Nm]";
tdmsreadprop(fileName, "ChannelGroupName",group_T1, "ChannelName", channel_T1);
data = tdmsread(fileName, "ChannelGroupName",group_T1, "ChannelName", channel_T1);
T1 = data{1};
group_T2 = "Torques";
channel_T2 = "T2 [Nm]";
tdmsreadprop(fileName, "ChannelGroupName",group_T2, "ChannelName", channel_T2);
data = tdmsread(fileName, "ChannelGroupName",group_T2, "ChannelName", channel_T2);
T2 = data{1};
group_T3 = "Torques";
channel_T3 = "T3 [Nm]";
tdmsreadprop(fileName, "ChannelGroupName",group_T3, "ChannelName", channel_T3);
data = tdmsread(fileName, "ChannelGroupName",group_T3, "ChannelName", channel_T3);
T3 = data{1};
group_T4 = "Torques";
channel_T4 = "T4 [Nm]";
tdmsreadprop(fileName, "ChannelGroupName",group_T4, "ChannelName", channel_T4);
data = tdmsread(fileName, "ChannelGroupName",group_T4, "ChannelName", channel_T4);
T4 = data{1};
group_T5 = "Torques";
channel_T5 = "T5 [Nm]";
tdmsreadprop(fileName, "ChannelGroupName",group_T5, "ChannelName", channel_T5);
data = tdmsread(fileName, "ChannelGroupName",group_T5, "ChannelName", channel_T5);
T5 = data{1};
group_T6 = "Torques";
channel_T6 = "T6 [Nm]";
tdmsreadprop(fileName, "ChannelGroupName",group_T6, "ChannelName", channel_T6);
data = tdmsread(fileName, "ChannelGroupName",group_T6, "ChannelName", channel_T6);
T6 = data{1};
group_T7 = "Torques";
channel_T7 = "T7 [Nm]";
tdmsreadprop(fileName, "ChannelGroupName",group_T7, "ChannelName", channel_T7);
data = tdmsread(fileName, "ChannelGroupName",group_T7, "ChannelName", channel_T7);
T7 = data{1};
group_T8 = "Torques";
channel_T8 = "T8 [Nm]";
tdmsreadprop(fileName, "ChannelGroupName",group_T8, "ChannelName", channel_T8);
data = tdmsread(fileName, "ChannelGroupName",group_T8, "ChannelName", channel_T8);
T8 = data{1};
%Current readings%
group_I1a = "Motor voltages and currents";
channel_I1a = "I1a [A]";
tdmsreadprop(fileName, "ChannelGroupName",group_I1a, "ChannelName", channel_I1a);
data = tdmsread(fileName, "ChannelGroupName",group_I1a, "ChannelName", channel_I1a);
I1a = data{1};
group_I1b = "Motor voltages and currents";
channel_I1b = "I1b [A]";
tdmsreadprop(fileName, "ChannelGroupName",group_I1b, "ChannelName", channel_I1b);
data = tdmsread(fileName, "ChannelGroupName",group_I1b, "ChannelName", channel_I1b);
I1b = data{1};
group_I1c = "Motor voltages and currents";
channel_I1c = "I1c [A]";
tdmsreadprop(fileName, "ChannelGroupName",group_I1c, "ChannelName", channel_I1c);
data = tdmsread(fileName, "ChannelGroupName",group_I1c, "ChannelName", channel_I1c);
I1c = data{1};
group_I2a = "Motor voltages and currents";
channel_I2a = "I2a [A]";
tdmsreadprop(fileName, "ChannelGroupName",group_I2a, "ChannelName", channel_I2a);
data = tdmsread(fileName, "ChannelGroupName",group_I2a, "ChannelName", channel_I2a);
I2a = data{1};
group_I2b = "Motor voltages and currents";
channel_I2b = "I2b [A]";
tdmsreadprop(fileName, "ChannelGroupName",group_I2b, "ChannelName", channel_I2b);
data = tdmsread(fileName, "ChannelGroupName",group_I2b, "ChannelName", channel_I2b);
I2b = data{1};
group_I2c = "Motor voltages and currents";
channel_I2c = "I2c [A]";
tdmsreadprop(fileName, "ChannelGroupName",group_I2c, "ChannelName", channel_I2c);
data = tdmsread(fileName, "ChannelGroupName",group_I2c, "ChannelName", channel_I2c);
I2c = data{1};
group_I3a = "Motor voltages and currents";
channel_I3a = "I3a [A]";
tdmsreadprop(fileName, "ChannelGroupName",group_I3a, "ChannelName", channel_I3a);
data = tdmsread(fileName, "ChannelGroupName",group_I3a, "ChannelName", channel_I3a);
I3a = data{1};
group_I3b = "Motor voltages and currents";
channel_I3b = "I3b [A]";
tdmsreadprop(fileName, "ChannelGroupName",group_I3b, "ChannelName", channel_I3b);
data = tdmsread(fileName, "ChannelGroupName",group_I3b, "ChannelName", channel_I3b);
I3b = data{1};
group_I3c = "Motor voltages and currents";
channel_I3c = "I3c [A]";
tdmsreadprop(fileName, "ChannelGroupName",group_I3c, "ChannelName", channel_I3c);
data = tdmsread(fileName, "ChannelGroupName",group_I3c, "ChannelName", channel_I3c);
I3c = data{1};
group_I4a = "Motor voltages and currents";
channel_I4a = "I4a [A]";
tdmsreadprop(fileName, "ChannelGroupName",group_I4a, "ChannelName", channel_I4a);
data = tdmsread(fileName, "ChannelGroupName",group_I4a, "ChannelName", channel_I4a);
I4a = data{1};
group_I4b = "Motor voltages and currents";
channel_I4b = "I4b [A]";
tdmsreadprop(fileName, "ChannelGroupName",group_I4b, "ChannelName", channel_I4b);
data = tdmsread(fileName, "ChannelGroupName",group_I4b, "ChannelName", channel_I4b);
I4b = data{1};
group_I4c = "Motor voltages and currents";
channel_I4c = "I4c [A]";
tdmsreadprop(fileName, "ChannelGroupName",group_I4c, "ChannelName", channel_I4c);
data = tdmsread(fileName, "ChannelGroupName",group_I4c, "ChannelName", channel_I4c);
I4c = data{1};
group_IDC = "Motor voltages and currents";
channel_IDC = "IDC [A]";
tdmsreadprop(fileName, "ChannelGroupName",group_IDC, "ChannelName", channel_IDC);
data = tdmsread(fileName, "ChannelGroupName",group_IDC, "ChannelName", channel_IDC);
IDC = data{1};
%Voltage readings%
group_V1ab = "Motor voltages and currents";
channel_V1ab = "V1ab [V]";
tdmsreadprop(fileName, "ChannelGroupName",group_V1ab, "ChannelName", channel_V1ab);
data = tdmsread(fileName, "ChannelGroupName",group_V1ab, "ChannelName", channel_V1ab);
V1ab = data{1};
group_V1bc = "Motor voltages and currents";
channel_V1bc = "V1bc [V]";
tdmsreadprop(fileName, "ChannelGroupName",group_V1bc, "ChannelName", channel_V1bc);
data = tdmsread(fileName, "ChannelGroupName",group_V1bc, "ChannelName", channel_V1bc);
V1bc = data{1};
group_V1ca = "Motor voltages and currents";
channel_V1ca = "V1ca [V]";
tdmsreadprop(fileName, "ChannelGroupName",group_V1ca, "ChannelName", channel_V1ca);
data = tdmsread(fileName, "ChannelGroupName",group_V1ca, "ChannelName", channel_V1ca);
V1ca = data{1};
group_V2ab = "Motor voltages and currents";
channel_V2ab = "V2ab [V]";
tdmsreadprop(fileName, "ChannelGroupName",group_V2ab, "ChannelName", channel_V2ab);
data = tdmsread(fileName, "ChannelGroupName",group_V2ab, "ChannelName", channel_V2ab);
V2ab = data{1};
group_V2bc = "Motor voltages and currents";
channel_V2bc = "V2bc [V]";
tdmsreadprop(fileName, "ChannelGroupName",group_V2bc, "ChannelName", channel_V2bc);
data = tdmsread(fileName, "ChannelGroupName",group_V2bc, "ChannelName", channel_V2bc);
V2bc = data{1};
group_V2ca = "Motor voltages and currents";
channel_V2ca = "V2ca [V]";
tdmsreadprop(fileName, "ChannelGroupName",group_V2ca, "ChannelName", channel_V2ca);
data = tdmsread(fileName, "ChannelGroupName",group_V2ca, "ChannelName", channel_V2ca);
V2ca = data{1};
group_V3ab = "Motor voltages and currents";
channel_V3ab = "V3ab [V]";
tdmsreadprop(fileName, "ChannelGroupName",group_V3ab, "ChannelName", channel_V3ab);
data = tdmsread(fileName, "ChannelGroupName",group_V3ab, "ChannelName", channel_V3ab);
V3ab = data{1};
group_V3bc = "Motor voltages and currents";
channel_V3bc = "V3bc [V]";
tdmsreadprop(fileName, "ChannelGroupName",group_V3bc, "ChannelName", channel_V3bc);
data = tdmsread(fileName, "ChannelGroupName",group_V3bc, "ChannelName", channel_V3bc);
V3bc = data{1};
group_V3ca = "Motor voltages and currents";
channel_V3ca = "V3ca [V]";
tdmsreadprop(fileName, "ChannelGroupName",group_V3ca, "ChannelName", channel_V3ca);
data = tdmsread(fileName, "ChannelGroupName",group_V3ca, "ChannelName", channel_V3ca);
V3ca = data{1};
group_V4ab = "Motor voltages and currents";
channel_V4ab = "V4ab [V]";
tdmsreadprop(fileName, "ChannelGroupName",group_V4ab, "ChannelName", channel_V4ab);
data = tdmsread(fileName, "ChannelGroupName",group_V4ab, "ChannelName", channel_V4ab);
V4ab = data{1};
group_V4bc = "Motor voltages and currents";
channel_V4bc = "V4bc [V]";
tdmsreadprop(fileName, "ChannelGroupName",group_V4bc, "ChannelName", channel_V4bc);
data = tdmsread(fileName, "ChannelGroupName",group_V4bc, "ChannelName", channel_V4bc);
V4bc = data{1};
group_V4ca = "Motor voltages and currents";
channel_V4ca = "V4ca [V]";
tdmsreadprop(fileName, "ChannelGroupName",group_V4ca, "ChannelName", channel_V4ca);
data = tdmsread(fileName, "ChannelGroupName",group_V4ca, "ChannelName", channel_V4ca);
V4ca = data{1};
group_VDC = "Motor voltages and currents";
channel_VDC = "VDC [V]";
tdmsreadprop(fileName, "ChannelGroupName",group_VDC, "ChannelName", channel_VDC);
data = tdmsread(fileName, "ChannelGroupName",group_VDC, "ChannelName", channel_VDC);
VDC = data{1};
% Control Commands- Speed
group_M5S = "Control commands";
channel_M5S = "M5 speed cmd [RPM]";
tdmsreadprop(fileName, "ChannelGroupName",group_M5S, "ChannelName", channel_M5S);
data = tdmsread(fileName, "ChannelGroupName",group_M5S, "ChannelName", channel_M5S);
M5S = data{1};
group_M6S = "Control commands";
channel_M6S = "M6 speed cmd [RPM]";
tdmsreadprop(fileName, "ChannelGroupName",group_M6S, "ChannelName", channel_M6S);
data = tdmsread(fileName, "ChannelGroupName",group_M6S, "ChannelName", channel_M6S);
M6S = data{1};
group_M7S = "Control commands";
channel_M7S = "M7 speed cmd [RPM]";
tdmsreadprop(fileName, "ChannelGroupName",group_M7S, "ChannelName", channel_M7S);
data = tdmsread(fileName, "ChannelGroupName",group_M7S, "ChannelName", channel_M7S);
M7S = data{1};
group_M8S = "Control commands";
channel_M8S = "M8 speed cmd [RPM]";
tdmsreadprop(fileName, "ChannelGroupName",group_M8S, "ChannelName", channel_M8S);
data = tdmsread(fileName, "ChannelGroupName",group_M8S, "ChannelName", channel_M8S);
M8S = data{1};
% Control Commands- Torque
group_M5T = "Control commands";
channel_M5T = "M5 torque cmd [Nm]";
tdmsreadprop(fileName, "ChannelGroupName",group_M5T, "ChannelName", channel_M5T);
data = tdmsread(fileName, "ChannelGroupName",group_M5T, "ChannelName", channel_M5T);
M5T = data{1};
group_M6T = "Control commands";
channel_M6T = "M6 torque cmd [Nm]";
tdmsreadprop(fileName, "ChannelGroupName",group_M6T, "ChannelName", channel_M6T);
data = tdmsread(fileName, "ChannelGroupName",group_M6T, "ChannelName", channel_M6T);
M6T = data{1};
group_M7T = "Control commands";
channel_M7T = "M7 torque cmd [Nm]";
tdmsreadprop(fileName, "ChannelGroupName",group_M7T, "ChannelName", channel_M7T);
data = tdmsread(fileName, "ChannelGroupName",group_M7T, "ChannelName", channel_M7T);
M7T = data{1};
group_M8T = "Control commands";
channel_M8T = "M8 torque cmd [Nm]";
tdmsreadprop(fileName, "ChannelGroupName",group_M8T, "ChannelName", channel_M8T);
data = tdmsread(fileName, "ChannelGroupName",group_M8T, "ChannelName", channel_M8T);
M8T = data{1};
%ARRAYS
N1 = table2array(N1);
N2 = table2array(N2);
N3 = table2array(N3);
N4 = table2array(N4);
N5 = table2array(N5);
N6 = table2array(N6);
N7 = table2array(N7);
N8 = table2array(N8);
T1 = table2array(T1);
T2 = table2array(T2);
T3 = table2array(T3);
T4 = table2array(T4);
T5 = table2array(T5);
T6 = table2array(T6);
T7 = table2array(T7);
T8 = table2array(T8);
I1a = table2array(I1a);
I2a = table2array(I2a);
I3a = table2array(I3a);
I4a = table2array(I4a);
I1b = table2array(I1b);
I2b = table2array(I2b);
I3b = table2array(I3b);
I4b = table2array(I4b);
I1c = table2array(I1c);
I2c = table2array(I2c);
I3c = table2array(I3c);
I4c = table2array(I4c);
IDC = table2array(IDC);
V1ab = table2array(V1ab);
V2ab = table2array(V2ab);
V3ab = table2array(V3ab);
V4ab = table2array(V4ab);
V1bc = table2array(V1bc);
V2bc = table2array(V2bc);
V3bc = table2array(V3bc);
V4bc = table2array(V4bc);
V1ca = table2array(V1ca);
V2ca = table2array(V2ca);
V3ca = table2array(V3ca);
V4ca = table2array(V4ca);
VDC= table2array(VDC);
M5S = table2array(M5S);
M6S = table2array(M6S);
M7S = table2array(M7S);
M8S = table2array(M8S);
M5T = table2array(M5T);
M6T = table2array(M6T);
M7T = table2array(M7T);
M8T = table2array(M8T);
% GRAPHS AND TIME STAMPS
minLength_1 = min([length(time), length(T1), length(I1a)]);
minLength_2 = min([length(time), length(T1), length(M5T)]);
time = time(1:minLength_1);
T5 = T5(1:minLength_1);
I1a = I1a(1:minLength_1);
M5T = M5T(1:minLength_2);
figure;
hold on;
subplot(2, 1, 1);
plot(time, T5, ‘r-‘, ‘DisplayName’, ‘T5 [Nm]’);
xlabel(‘Time (s)’);
ylabel(‘T5 [Nm]’);
title(‘T5 vs. Time’);
legend(‘show’);
subplot(2, 1, 2);
plot(time, M5T, ‘b-‘, ‘DisplayName’, ‘M5T [Nm]’);
xlabel(‘Time (s)’);
ylabel(‘M5T [Nm]’);
title(‘M5T vs. Time’);
legend(‘show’);
legend;
hold off;
[~, maxIdx] = max(T5);
maxTime = time(maxIdx);
zeroCrossIdx = find(T5(maxIdx:end) <= 0, 1, ‘first’) + maxIdx – 1;
if isempty(zeroCrossIdx)
timeToZero = NaN;
disp(‘Data does not return to zero after maximum.’);
else
timeToZero = time(zeroCrossIdx) – maxTime;
disp(timeToZero);
end
% Find the index where interpolated T5 matches M5
matchIndex = find(T5 == M5T);
if isempty(matchIndex)
disp(‘T5 does not match M5 ‘);
else
matchTime = commonTime(matchIndex);
fprintf(‘T5 matches M5 at t = %.2f seconds (interpolated).n’, matchTime);
endI am trying to read multiple groups and channels of a TDMS file and doing some graphing and calculations at the end. I need to be able to acceses any channel or group that I want to use in the graphs or calcualtions, I would really apperciate it if someone had any advice on sliming the code down it currently takes 6 mins to run which is a really long time.
defaultFolder = ‘C:UserslillypColostateLute,Chris – EM-TRAS internalMatlab’;
addpath(defaultFolder);
fileFilter = ‘*.tdms’;
[fileName, filepath] = uigetfile(fullfile(defaultFolder, fileFilter), ‘Select a TDMS file’);
if fileName ~= 0
fullFilePath = fullfile(filepath, fileName);
disp([‘Selected file: ‘, fullFilePath]);
else
disp(‘No file selected.’);
end
fileName = fullFilePath;
group_Time = "Torques";
channel_Time = "Timestamp";
tdmsreadprop(fileName, "ChannelGroupName",group_Time, "ChannelName", channel_Time);
data = tdmsread(fileName, "ChannelGroupName",group_Time, "ChannelName", channel_Time);
time = data{1};
if istable(time)
time = table2array(time);
elseif isdatetime(time)
time = seconds(time – time(1));
end
% Speed readings%
group_N1 = "Rotary encoders";
channel_N1 = "N1 [RPM]";
tdmsreadprop(fileName, "ChannelGroupName",group_N1, "ChannelName", channel_N1);
data = tdmsread(fileName, "ChannelGroupName",group_N1, "ChannelName", channel_N1);
N1 = data{1};
group_N2 = "Rotary encoders";
channel_N2 = "N2 [RPM]";
tdmsreadprop(fileName, "ChannelGroupName",group_N2, "ChannelName", channel_N2);
data = tdmsread(fileName, "ChannelGroupName",group_N2, "ChannelName", channel_N2);
N2 = data{1};
group_N3 = "Rotary encoders";
channel_N3 = "N3 [RPM]";
tdmsreadprop(fileName, "ChannelGroupName",group_N3, "ChannelName", channel_N3);
data = tdmsread(fileName, "ChannelGroupName",group_N3, "ChannelName", channel_N3);
N3 = data{1};
group_N4 = "Rotary encoders";
channel_N4 = "N4 [RPM]";
tdmsreadprop(fileName, "ChannelGroupName",group_N4, "ChannelName", channel_N4);
data = tdmsread(fileName, "ChannelGroupName",group_N4, "ChannelName", channel_N4);
N4 = data{1};
group_N5 = "Rotary encoders";
channel_N5 = "N5 [RPM]";
tdmsreadprop(fileName, "ChannelGroupName",group_N5, "ChannelName", channel_N5);
data = tdmsread(fileName, "ChannelGroupName",group_N5, "ChannelName", channel_N5);
N5 = data{1};
group_N6 = "Rotary encoders";
channel_N6 = "N6 [RPM]";
tdmsreadprop(fileName, "ChannelGroupName",group_N6, "ChannelName", channel_N6);
data = tdmsread(fileName, "ChannelGroupName",group_N6, "ChannelName", channel_N6);
N6 = data{1};
group_N7 = "Rotary encoders";
channel_N7 = "N7 [RPM]";
tdmsreadprop(fileName, "ChannelGroupName",group_N7, "ChannelName", channel_N7);
data = tdmsread(fileName, "ChannelGroupName",group_N7, "ChannelName", channel_N7);
N7 = data{1};
group_N8 = "Rotary encoders";
channel_N8 = "N8 [RPM]";
tdmsreadprop(fileName, "ChannelGroupName",group_N8, "ChannelName", channel_N8);
data = tdmsread(fileName, "ChannelGroupName",group_N8, "ChannelName", channel_N8);
N8 = data{1};
% Torque readings%
group_T1 = "Torques";
channel_T1 = "T1 [Nm]";
tdmsreadprop(fileName, "ChannelGroupName",group_T1, "ChannelName", channel_T1);
data = tdmsread(fileName, "ChannelGroupName",group_T1, "ChannelName", channel_T1);
T1 = data{1};
group_T2 = "Torques";
channel_T2 = "T2 [Nm]";
tdmsreadprop(fileName, "ChannelGroupName",group_T2, "ChannelName", channel_T2);
data = tdmsread(fileName, "ChannelGroupName",group_T2, "ChannelName", channel_T2);
T2 = data{1};
group_T3 = "Torques";
channel_T3 = "T3 [Nm]";
tdmsreadprop(fileName, "ChannelGroupName",group_T3, "ChannelName", channel_T3);
data = tdmsread(fileName, "ChannelGroupName",group_T3, "ChannelName", channel_T3);
T3 = data{1};
group_T4 = "Torques";
channel_T4 = "T4 [Nm]";
tdmsreadprop(fileName, "ChannelGroupName",group_T4, "ChannelName", channel_T4);
data = tdmsread(fileName, "ChannelGroupName",group_T4, "ChannelName", channel_T4);
T4 = data{1};
group_T5 = "Torques";
channel_T5 = "T5 [Nm]";
tdmsreadprop(fileName, "ChannelGroupName",group_T5, "ChannelName", channel_T5);
data = tdmsread(fileName, "ChannelGroupName",group_T5, "ChannelName", channel_T5);
T5 = data{1};
group_T6 = "Torques";
channel_T6 = "T6 [Nm]";
tdmsreadprop(fileName, "ChannelGroupName",group_T6, "ChannelName", channel_T6);
data = tdmsread(fileName, "ChannelGroupName",group_T6, "ChannelName", channel_T6);
T6 = data{1};
group_T7 = "Torques";
channel_T7 = "T7 [Nm]";
tdmsreadprop(fileName, "ChannelGroupName",group_T7, "ChannelName", channel_T7);
data = tdmsread(fileName, "ChannelGroupName",group_T7, "ChannelName", channel_T7);
T7 = data{1};
group_T8 = "Torques";
channel_T8 = "T8 [Nm]";
tdmsreadprop(fileName, "ChannelGroupName",group_T8, "ChannelName", channel_T8);
data = tdmsread(fileName, "ChannelGroupName",group_T8, "ChannelName", channel_T8);
T8 = data{1};
%Current readings%
group_I1a = "Motor voltages and currents";
channel_I1a = "I1a [A]";
tdmsreadprop(fileName, "ChannelGroupName",group_I1a, "ChannelName", channel_I1a);
data = tdmsread(fileName, "ChannelGroupName",group_I1a, "ChannelName", channel_I1a);
I1a = data{1};
group_I1b = "Motor voltages and currents";
channel_I1b = "I1b [A]";
tdmsreadprop(fileName, "ChannelGroupName",group_I1b, "ChannelName", channel_I1b);
data = tdmsread(fileName, "ChannelGroupName",group_I1b, "ChannelName", channel_I1b);
I1b = data{1};
group_I1c = "Motor voltages and currents";
channel_I1c = "I1c [A]";
tdmsreadprop(fileName, "ChannelGroupName",group_I1c, "ChannelName", channel_I1c);
data = tdmsread(fileName, "ChannelGroupName",group_I1c, "ChannelName", channel_I1c);
I1c = data{1};
group_I2a = "Motor voltages and currents";
channel_I2a = "I2a [A]";
tdmsreadprop(fileName, "ChannelGroupName",group_I2a, "ChannelName", channel_I2a);
data = tdmsread(fileName, "ChannelGroupName",group_I2a, "ChannelName", channel_I2a);
I2a = data{1};
group_I2b = "Motor voltages and currents";
channel_I2b = "I2b [A]";
tdmsreadprop(fileName, "ChannelGroupName",group_I2b, "ChannelName", channel_I2b);
data = tdmsread(fileName, "ChannelGroupName",group_I2b, "ChannelName", channel_I2b);
I2b = data{1};
group_I2c = "Motor voltages and currents";
channel_I2c = "I2c [A]";
tdmsreadprop(fileName, "ChannelGroupName",group_I2c, "ChannelName", channel_I2c);
data = tdmsread(fileName, "ChannelGroupName",group_I2c, "ChannelName", channel_I2c);
I2c = data{1};
group_I3a = "Motor voltages and currents";
channel_I3a = "I3a [A]";
tdmsreadprop(fileName, "ChannelGroupName",group_I3a, "ChannelName", channel_I3a);
data = tdmsread(fileName, "ChannelGroupName",group_I3a, "ChannelName", channel_I3a);
I3a = data{1};
group_I3b = "Motor voltages and currents";
channel_I3b = "I3b [A]";
tdmsreadprop(fileName, "ChannelGroupName",group_I3b, "ChannelName", channel_I3b);
data = tdmsread(fileName, "ChannelGroupName",group_I3b, "ChannelName", channel_I3b);
I3b = data{1};
group_I3c = "Motor voltages and currents";
channel_I3c = "I3c [A]";
tdmsreadprop(fileName, "ChannelGroupName",group_I3c, "ChannelName", channel_I3c);
data = tdmsread(fileName, "ChannelGroupName",group_I3c, "ChannelName", channel_I3c);
I3c = data{1};
group_I4a = "Motor voltages and currents";
channel_I4a = "I4a [A]";
tdmsreadprop(fileName, "ChannelGroupName",group_I4a, "ChannelName", channel_I4a);
data = tdmsread(fileName, "ChannelGroupName",group_I4a, "ChannelName", channel_I4a);
I4a = data{1};
group_I4b = "Motor voltages and currents";
channel_I4b = "I4b [A]";
tdmsreadprop(fileName, "ChannelGroupName",group_I4b, "ChannelName", channel_I4b);
data = tdmsread(fileName, "ChannelGroupName",group_I4b, "ChannelName", channel_I4b);
I4b = data{1};
group_I4c = "Motor voltages and currents";
channel_I4c = "I4c [A]";
tdmsreadprop(fileName, "ChannelGroupName",group_I4c, "ChannelName", channel_I4c);
data = tdmsread(fileName, "ChannelGroupName",group_I4c, "ChannelName", channel_I4c);
I4c = data{1};
group_IDC = "Motor voltages and currents";
channel_IDC = "IDC [A]";
tdmsreadprop(fileName, "ChannelGroupName",group_IDC, "ChannelName", channel_IDC);
data = tdmsread(fileName, "ChannelGroupName",group_IDC, "ChannelName", channel_IDC);
IDC = data{1};
%Voltage readings%
group_V1ab = "Motor voltages and currents";
channel_V1ab = "V1ab [V]";
tdmsreadprop(fileName, "ChannelGroupName",group_V1ab, "ChannelName", channel_V1ab);
data = tdmsread(fileName, "ChannelGroupName",group_V1ab, "ChannelName", channel_V1ab);
V1ab = data{1};
group_V1bc = "Motor voltages and currents";
channel_V1bc = "V1bc [V]";
tdmsreadprop(fileName, "ChannelGroupName",group_V1bc, "ChannelName", channel_V1bc);
data = tdmsread(fileName, "ChannelGroupName",group_V1bc, "ChannelName", channel_V1bc);
V1bc = data{1};
group_V1ca = "Motor voltages and currents";
channel_V1ca = "V1ca [V]";
tdmsreadprop(fileName, "ChannelGroupName",group_V1ca, "ChannelName", channel_V1ca);
data = tdmsread(fileName, "ChannelGroupName",group_V1ca, "ChannelName", channel_V1ca);
V1ca = data{1};
group_V2ab = "Motor voltages and currents";
channel_V2ab = "V2ab [V]";
tdmsreadprop(fileName, "ChannelGroupName",group_V2ab, "ChannelName", channel_V2ab);
data = tdmsread(fileName, "ChannelGroupName",group_V2ab, "ChannelName", channel_V2ab);
V2ab = data{1};
group_V2bc = "Motor voltages and currents";
channel_V2bc = "V2bc [V]";
tdmsreadprop(fileName, "ChannelGroupName",group_V2bc, "ChannelName", channel_V2bc);
data = tdmsread(fileName, "ChannelGroupName",group_V2bc, "ChannelName", channel_V2bc);
V2bc = data{1};
group_V2ca = "Motor voltages and currents";
channel_V2ca = "V2ca [V]";
tdmsreadprop(fileName, "ChannelGroupName",group_V2ca, "ChannelName", channel_V2ca);
data = tdmsread(fileName, "ChannelGroupName",group_V2ca, "ChannelName", channel_V2ca);
V2ca = data{1};
group_V3ab = "Motor voltages and currents";
channel_V3ab = "V3ab [V]";
tdmsreadprop(fileName, "ChannelGroupName",group_V3ab, "ChannelName", channel_V3ab);
data = tdmsread(fileName, "ChannelGroupName",group_V3ab, "ChannelName", channel_V3ab);
V3ab = data{1};
group_V3bc = "Motor voltages and currents";
channel_V3bc = "V3bc [V]";
tdmsreadprop(fileName, "ChannelGroupName",group_V3bc, "ChannelName", channel_V3bc);
data = tdmsread(fileName, "ChannelGroupName",group_V3bc, "ChannelName", channel_V3bc);
V3bc = data{1};
group_V3ca = "Motor voltages and currents";
channel_V3ca = "V3ca [V]";
tdmsreadprop(fileName, "ChannelGroupName",group_V3ca, "ChannelName", channel_V3ca);
data = tdmsread(fileName, "ChannelGroupName",group_V3ca, "ChannelName", channel_V3ca);
V3ca = data{1};
group_V4ab = "Motor voltages and currents";
channel_V4ab = "V4ab [V]";
tdmsreadprop(fileName, "ChannelGroupName",group_V4ab, "ChannelName", channel_V4ab);
data = tdmsread(fileName, "ChannelGroupName",group_V4ab, "ChannelName", channel_V4ab);
V4ab = data{1};
group_V4bc = "Motor voltages and currents";
channel_V4bc = "V4bc [V]";
tdmsreadprop(fileName, "ChannelGroupName",group_V4bc, "ChannelName", channel_V4bc);
data = tdmsread(fileName, "ChannelGroupName",group_V4bc, "ChannelName", channel_V4bc);
V4bc = data{1};
group_V4ca = "Motor voltages and currents";
channel_V4ca = "V4ca [V]";
tdmsreadprop(fileName, "ChannelGroupName",group_V4ca, "ChannelName", channel_V4ca);
data = tdmsread(fileName, "ChannelGroupName",group_V4ca, "ChannelName", channel_V4ca);
V4ca = data{1};
group_VDC = "Motor voltages and currents";
channel_VDC = "VDC [V]";
tdmsreadprop(fileName, "ChannelGroupName",group_VDC, "ChannelName", channel_VDC);
data = tdmsread(fileName, "ChannelGroupName",group_VDC, "ChannelName", channel_VDC);
VDC = data{1};
% Control Commands- Speed
group_M5S = "Control commands";
channel_M5S = "M5 speed cmd [RPM]";
tdmsreadprop(fileName, "ChannelGroupName",group_M5S, "ChannelName", channel_M5S);
data = tdmsread(fileName, "ChannelGroupName",group_M5S, "ChannelName", channel_M5S);
M5S = data{1};
group_M6S = "Control commands";
channel_M6S = "M6 speed cmd [RPM]";
tdmsreadprop(fileName, "ChannelGroupName",group_M6S, "ChannelName", channel_M6S);
data = tdmsread(fileName, "ChannelGroupName",group_M6S, "ChannelName", channel_M6S);
M6S = data{1};
group_M7S = "Control commands";
channel_M7S = "M7 speed cmd [RPM]";
tdmsreadprop(fileName, "ChannelGroupName",group_M7S, "ChannelName", channel_M7S);
data = tdmsread(fileName, "ChannelGroupName",group_M7S, "ChannelName", channel_M7S);
M7S = data{1};
group_M8S = "Control commands";
channel_M8S = "M8 speed cmd [RPM]";
tdmsreadprop(fileName, "ChannelGroupName",group_M8S, "ChannelName", channel_M8S);
data = tdmsread(fileName, "ChannelGroupName",group_M8S, "ChannelName", channel_M8S);
M8S = data{1};
% Control Commands- Torque
group_M5T = "Control commands";
channel_M5T = "M5 torque cmd [Nm]";
tdmsreadprop(fileName, "ChannelGroupName",group_M5T, "ChannelName", channel_M5T);
data = tdmsread(fileName, "ChannelGroupName",group_M5T, "ChannelName", channel_M5T);
M5T = data{1};
group_M6T = "Control commands";
channel_M6T = "M6 torque cmd [Nm]";
tdmsreadprop(fileName, "ChannelGroupName",group_M6T, "ChannelName", channel_M6T);
data = tdmsread(fileName, "ChannelGroupName",group_M6T, "ChannelName", channel_M6T);
M6T = data{1};
group_M7T = "Control commands";
channel_M7T = "M7 torque cmd [Nm]";
tdmsreadprop(fileName, "ChannelGroupName",group_M7T, "ChannelName", channel_M7T);
data = tdmsread(fileName, "ChannelGroupName",group_M7T, "ChannelName", channel_M7T);
M7T = data{1};
group_M8T = "Control commands";
channel_M8T = "M8 torque cmd [Nm]";
tdmsreadprop(fileName, "ChannelGroupName",group_M8T, "ChannelName", channel_M8T);
data = tdmsread(fileName, "ChannelGroupName",group_M8T, "ChannelName", channel_M8T);
M8T = data{1};
%ARRAYS
N1 = table2array(N1);
N2 = table2array(N2);
N3 = table2array(N3);
N4 = table2array(N4);
N5 = table2array(N5);
N6 = table2array(N6);
N7 = table2array(N7);
N8 = table2array(N8);
T1 = table2array(T1);
T2 = table2array(T2);
T3 = table2array(T3);
T4 = table2array(T4);
T5 = table2array(T5);
T6 = table2array(T6);
T7 = table2array(T7);
T8 = table2array(T8);
I1a = table2array(I1a);
I2a = table2array(I2a);
I3a = table2array(I3a);
I4a = table2array(I4a);
I1b = table2array(I1b);
I2b = table2array(I2b);
I3b = table2array(I3b);
I4b = table2array(I4b);
I1c = table2array(I1c);
I2c = table2array(I2c);
I3c = table2array(I3c);
I4c = table2array(I4c);
IDC = table2array(IDC);
V1ab = table2array(V1ab);
V2ab = table2array(V2ab);
V3ab = table2array(V3ab);
V4ab = table2array(V4ab);
V1bc = table2array(V1bc);
V2bc = table2array(V2bc);
V3bc = table2array(V3bc);
V4bc = table2array(V4bc);
V1ca = table2array(V1ca);
V2ca = table2array(V2ca);
V3ca = table2array(V3ca);
V4ca = table2array(V4ca);
VDC= table2array(VDC);
M5S = table2array(M5S);
M6S = table2array(M6S);
M7S = table2array(M7S);
M8S = table2array(M8S);
M5T = table2array(M5T);
M6T = table2array(M6T);
M7T = table2array(M7T);
M8T = table2array(M8T);
% GRAPHS AND TIME STAMPS
minLength_1 = min([length(time), length(T1), length(I1a)]);
minLength_2 = min([length(time), length(T1), length(M5T)]);
time = time(1:minLength_1);
T5 = T5(1:minLength_1);
I1a = I1a(1:minLength_1);
M5T = M5T(1:minLength_2);
figure;
hold on;
subplot(2, 1, 1);
plot(time, T5, ‘r-‘, ‘DisplayName’, ‘T5 [Nm]’);
xlabel(‘Time (s)’);
ylabel(‘T5 [Nm]’);
title(‘T5 vs. Time’);
legend(‘show’);
subplot(2, 1, 2);
plot(time, M5T, ‘b-‘, ‘DisplayName’, ‘M5T [Nm]’);
xlabel(‘Time (s)’);
ylabel(‘M5T [Nm]’);
title(‘M5T vs. Time’);
legend(‘show’);
legend;
hold off;
[~, maxIdx] = max(T5);
maxTime = time(maxIdx);
zeroCrossIdx = find(T5(maxIdx:end) <= 0, 1, ‘first’) + maxIdx – 1;
if isempty(zeroCrossIdx)
timeToZero = NaN;
disp(‘Data does not return to zero after maximum.’);
else
timeToZero = time(zeroCrossIdx) – maxTime;
disp(timeToZero);
end
% Find the index where interpolated T5 matches M5
matchIndex = find(T5 == M5T);
if isempty(matchIndex)
disp(‘T5 does not match M5 ‘);
else
matchTime = commonTime(matchIndex);
fprintf(‘T5 matches M5 at t = %.2f seconds (interpolated).n’, matchTime);
end I am trying to read multiple groups and channels of a TDMS file and doing some graphing and calculations at the end. I need to be able to acceses any channel or group that I want to use in the graphs or calcualtions, I would really apperciate it if someone had any advice on sliming the code down it currently takes 6 mins to run which is a really long time.
defaultFolder = ‘C:UserslillypColostateLute,Chris – EM-TRAS internalMatlab’;
addpath(defaultFolder);
fileFilter = ‘*.tdms’;
[fileName, filepath] = uigetfile(fullfile(defaultFolder, fileFilter), ‘Select a TDMS file’);
if fileName ~= 0
fullFilePath = fullfile(filepath, fileName);
disp([‘Selected file: ‘, fullFilePath]);
else
disp(‘No file selected.’);
end
fileName = fullFilePath;
group_Time = "Torques";
channel_Time = "Timestamp";
tdmsreadprop(fileName, "ChannelGroupName",group_Time, "ChannelName", channel_Time);
data = tdmsread(fileName, "ChannelGroupName",group_Time, "ChannelName", channel_Time);
time = data{1};
if istable(time)
time = table2array(time);
elseif isdatetime(time)
time = seconds(time – time(1));
end
% Speed readings%
group_N1 = "Rotary encoders";
channel_N1 = "N1 [RPM]";
tdmsreadprop(fileName, "ChannelGroupName",group_N1, "ChannelName", channel_N1);
data = tdmsread(fileName, "ChannelGroupName",group_N1, "ChannelName", channel_N1);
N1 = data{1};
group_N2 = "Rotary encoders";
channel_N2 = "N2 [RPM]";
tdmsreadprop(fileName, "ChannelGroupName",group_N2, "ChannelName", channel_N2);
data = tdmsread(fileName, "ChannelGroupName",group_N2, "ChannelName", channel_N2);
N2 = data{1};
group_N3 = "Rotary encoders";
channel_N3 = "N3 [RPM]";
tdmsreadprop(fileName, "ChannelGroupName",group_N3, "ChannelName", channel_N3);
data = tdmsread(fileName, "ChannelGroupName",group_N3, "ChannelName", channel_N3);
N3 = data{1};
group_N4 = "Rotary encoders";
channel_N4 = "N4 [RPM]";
tdmsreadprop(fileName, "ChannelGroupName",group_N4, "ChannelName", channel_N4);
data = tdmsread(fileName, "ChannelGroupName",group_N4, "ChannelName", channel_N4);
N4 = data{1};
group_N5 = "Rotary encoders";
channel_N5 = "N5 [RPM]";
tdmsreadprop(fileName, "ChannelGroupName",group_N5, "ChannelName", channel_N5);
data = tdmsread(fileName, "ChannelGroupName",group_N5, "ChannelName", channel_N5);
N5 = data{1};
group_N6 = "Rotary encoders";
channel_N6 = "N6 [RPM]";
tdmsreadprop(fileName, "ChannelGroupName",group_N6, "ChannelName", channel_N6);
data = tdmsread(fileName, "ChannelGroupName",group_N6, "ChannelName", channel_N6);
N6 = data{1};
group_N7 = "Rotary encoders";
channel_N7 = "N7 [RPM]";
tdmsreadprop(fileName, "ChannelGroupName",group_N7, "ChannelName", channel_N7);
data = tdmsread(fileName, "ChannelGroupName",group_N7, "ChannelName", channel_N7);
N7 = data{1};
group_N8 = "Rotary encoders";
channel_N8 = "N8 [RPM]";
tdmsreadprop(fileName, "ChannelGroupName",group_N8, "ChannelName", channel_N8);
data = tdmsread(fileName, "ChannelGroupName",group_N8, "ChannelName", channel_N8);
N8 = data{1};
% Torque readings%
group_T1 = "Torques";
channel_T1 = "T1 [Nm]";
tdmsreadprop(fileName, "ChannelGroupName",group_T1, "ChannelName", channel_T1);
data = tdmsread(fileName, "ChannelGroupName",group_T1, "ChannelName", channel_T1);
T1 = data{1};
group_T2 = "Torques";
channel_T2 = "T2 [Nm]";
tdmsreadprop(fileName, "ChannelGroupName",group_T2, "ChannelName", channel_T2);
data = tdmsread(fileName, "ChannelGroupName",group_T2, "ChannelName", channel_T2);
T2 = data{1};
group_T3 = "Torques";
channel_T3 = "T3 [Nm]";
tdmsreadprop(fileName, "ChannelGroupName",group_T3, "ChannelName", channel_T3);
data = tdmsread(fileName, "ChannelGroupName",group_T3, "ChannelName", channel_T3);
T3 = data{1};
group_T4 = "Torques";
channel_T4 = "T4 [Nm]";
tdmsreadprop(fileName, "ChannelGroupName",group_T4, "ChannelName", channel_T4);
data = tdmsread(fileName, "ChannelGroupName",group_T4, "ChannelName", channel_T4);
T4 = data{1};
group_T5 = "Torques";
channel_T5 = "T5 [Nm]";
tdmsreadprop(fileName, "ChannelGroupName",group_T5, "ChannelName", channel_T5);
data = tdmsread(fileName, "ChannelGroupName",group_T5, "ChannelName", channel_T5);
T5 = data{1};
group_T6 = "Torques";
channel_T6 = "T6 [Nm]";
tdmsreadprop(fileName, "ChannelGroupName",group_T6, "ChannelName", channel_T6);
data = tdmsread(fileName, "ChannelGroupName",group_T6, "ChannelName", channel_T6);
T6 = data{1};
group_T7 = "Torques";
channel_T7 = "T7 [Nm]";
tdmsreadprop(fileName, "ChannelGroupName",group_T7, "ChannelName", channel_T7);
data = tdmsread(fileName, "ChannelGroupName",group_T7, "ChannelName", channel_T7);
T7 = data{1};
group_T8 = "Torques";
channel_T8 = "T8 [Nm]";
tdmsreadprop(fileName, "ChannelGroupName",group_T8, "ChannelName", channel_T8);
data = tdmsread(fileName, "ChannelGroupName",group_T8, "ChannelName", channel_T8);
T8 = data{1};
%Current readings%
group_I1a = "Motor voltages and currents";
channel_I1a = "I1a [A]";
tdmsreadprop(fileName, "ChannelGroupName",group_I1a, "ChannelName", channel_I1a);
data = tdmsread(fileName, "ChannelGroupName",group_I1a, "ChannelName", channel_I1a);
I1a = data{1};
group_I1b = "Motor voltages and currents";
channel_I1b = "I1b [A]";
tdmsreadprop(fileName, "ChannelGroupName",group_I1b, "ChannelName", channel_I1b);
data = tdmsread(fileName, "ChannelGroupName",group_I1b, "ChannelName", channel_I1b);
I1b = data{1};
group_I1c = "Motor voltages and currents";
channel_I1c = "I1c [A]";
tdmsreadprop(fileName, "ChannelGroupName",group_I1c, "ChannelName", channel_I1c);
data = tdmsread(fileName, "ChannelGroupName",group_I1c, "ChannelName", channel_I1c);
I1c = data{1};
group_I2a = "Motor voltages and currents";
channel_I2a = "I2a [A]";
tdmsreadprop(fileName, "ChannelGroupName",group_I2a, "ChannelName", channel_I2a);
data = tdmsread(fileName, "ChannelGroupName",group_I2a, "ChannelName", channel_I2a);
I2a = data{1};
group_I2b = "Motor voltages and currents";
channel_I2b = "I2b [A]";
tdmsreadprop(fileName, "ChannelGroupName",group_I2b, "ChannelName", channel_I2b);
data = tdmsread(fileName, "ChannelGroupName",group_I2b, "ChannelName", channel_I2b);
I2b = data{1};
group_I2c = "Motor voltages and currents";
channel_I2c = "I2c [A]";
tdmsreadprop(fileName, "ChannelGroupName",group_I2c, "ChannelName", channel_I2c);
data = tdmsread(fileName, "ChannelGroupName",group_I2c, "ChannelName", channel_I2c);
I2c = data{1};
group_I3a = "Motor voltages and currents";
channel_I3a = "I3a [A]";
tdmsreadprop(fileName, "ChannelGroupName",group_I3a, "ChannelName", channel_I3a);
data = tdmsread(fileName, "ChannelGroupName",group_I3a, "ChannelName", channel_I3a);
I3a = data{1};
group_I3b = "Motor voltages and currents";
channel_I3b = "I3b [A]";
tdmsreadprop(fileName, "ChannelGroupName",group_I3b, "ChannelName", channel_I3b);
data = tdmsread(fileName, "ChannelGroupName",group_I3b, "ChannelName", channel_I3b);
I3b = data{1};
group_I3c = "Motor voltages and currents";
channel_I3c = "I3c [A]";
tdmsreadprop(fileName, "ChannelGroupName",group_I3c, "ChannelName", channel_I3c);
data = tdmsread(fileName, "ChannelGroupName",group_I3c, "ChannelName", channel_I3c);
I3c = data{1};
group_I4a = "Motor voltages and currents";
channel_I4a = "I4a [A]";
tdmsreadprop(fileName, "ChannelGroupName",group_I4a, "ChannelName", channel_I4a);
data = tdmsread(fileName, "ChannelGroupName",group_I4a, "ChannelName", channel_I4a);
I4a = data{1};
group_I4b = "Motor voltages and currents";
channel_I4b = "I4b [A]";
tdmsreadprop(fileName, "ChannelGroupName",group_I4b, "ChannelName", channel_I4b);
data = tdmsread(fileName, "ChannelGroupName",group_I4b, "ChannelName", channel_I4b);
I4b = data{1};
group_I4c = "Motor voltages and currents";
channel_I4c = "I4c [A]";
tdmsreadprop(fileName, "ChannelGroupName",group_I4c, "ChannelName", channel_I4c);
data = tdmsread(fileName, "ChannelGroupName",group_I4c, "ChannelName", channel_I4c);
I4c = data{1};
group_IDC = "Motor voltages and currents";
channel_IDC = "IDC [A]";
tdmsreadprop(fileName, "ChannelGroupName",group_IDC, "ChannelName", channel_IDC);
data = tdmsread(fileName, "ChannelGroupName",group_IDC, "ChannelName", channel_IDC);
IDC = data{1};
%Voltage readings%
group_V1ab = "Motor voltages and currents";
channel_V1ab = "V1ab [V]";
tdmsreadprop(fileName, "ChannelGroupName",group_V1ab, "ChannelName", channel_V1ab);
data = tdmsread(fileName, "ChannelGroupName",group_V1ab, "ChannelName", channel_V1ab);
V1ab = data{1};
group_V1bc = "Motor voltages and currents";
channel_V1bc = "V1bc [V]";
tdmsreadprop(fileName, "ChannelGroupName",group_V1bc, "ChannelName", channel_V1bc);
data = tdmsread(fileName, "ChannelGroupName",group_V1bc, "ChannelName", channel_V1bc);
V1bc = data{1};
group_V1ca = "Motor voltages and currents";
channel_V1ca = "V1ca [V]";
tdmsreadprop(fileName, "ChannelGroupName",group_V1ca, "ChannelName", channel_V1ca);
data = tdmsread(fileName, "ChannelGroupName",group_V1ca, "ChannelName", channel_V1ca);
V1ca = data{1};
group_V2ab = "Motor voltages and currents";
channel_V2ab = "V2ab [V]";
tdmsreadprop(fileName, "ChannelGroupName",group_V2ab, "ChannelName", channel_V2ab);
data = tdmsread(fileName, "ChannelGroupName",group_V2ab, "ChannelName", channel_V2ab);
V2ab = data{1};
group_V2bc = "Motor voltages and currents";
channel_V2bc = "V2bc [V]";
tdmsreadprop(fileName, "ChannelGroupName",group_V2bc, "ChannelName", channel_V2bc);
data = tdmsread(fileName, "ChannelGroupName",group_V2bc, "ChannelName", channel_V2bc);
V2bc = data{1};
group_V2ca = "Motor voltages and currents";
channel_V2ca = "V2ca [V]";
tdmsreadprop(fileName, "ChannelGroupName",group_V2ca, "ChannelName", channel_V2ca);
data = tdmsread(fileName, "ChannelGroupName",group_V2ca, "ChannelName", channel_V2ca);
V2ca = data{1};
group_V3ab = "Motor voltages and currents";
channel_V3ab = "V3ab [V]";
tdmsreadprop(fileName, "ChannelGroupName",group_V3ab, "ChannelName", channel_V3ab);
data = tdmsread(fileName, "ChannelGroupName",group_V3ab, "ChannelName", channel_V3ab);
V3ab = data{1};
group_V3bc = "Motor voltages and currents";
channel_V3bc = "V3bc [V]";
tdmsreadprop(fileName, "ChannelGroupName",group_V3bc, "ChannelName", channel_V3bc);
data = tdmsread(fileName, "ChannelGroupName",group_V3bc, "ChannelName", channel_V3bc);
V3bc = data{1};
group_V3ca = "Motor voltages and currents";
channel_V3ca = "V3ca [V]";
tdmsreadprop(fileName, "ChannelGroupName",group_V3ca, "ChannelName", channel_V3ca);
data = tdmsread(fileName, "ChannelGroupName",group_V3ca, "ChannelName", channel_V3ca);
V3ca = data{1};
group_V4ab = "Motor voltages and currents";
channel_V4ab = "V4ab [V]";
tdmsreadprop(fileName, "ChannelGroupName",group_V4ab, "ChannelName", channel_V4ab);
data = tdmsread(fileName, "ChannelGroupName",group_V4ab, "ChannelName", channel_V4ab);
V4ab = data{1};
group_V4bc = "Motor voltages and currents";
channel_V4bc = "V4bc [V]";
tdmsreadprop(fileName, "ChannelGroupName",group_V4bc, "ChannelName", channel_V4bc);
data = tdmsread(fileName, "ChannelGroupName",group_V4bc, "ChannelName", channel_V4bc);
V4bc = data{1};
group_V4ca = "Motor voltages and currents";
channel_V4ca = "V4ca [V]";
tdmsreadprop(fileName, "ChannelGroupName",group_V4ca, "ChannelName", channel_V4ca);
data = tdmsread(fileName, "ChannelGroupName",group_V4ca, "ChannelName", channel_V4ca);
V4ca = data{1};
group_VDC = "Motor voltages and currents";
channel_VDC = "VDC [V]";
tdmsreadprop(fileName, "ChannelGroupName",group_VDC, "ChannelName", channel_VDC);
data = tdmsread(fileName, "ChannelGroupName",group_VDC, "ChannelName", channel_VDC);
VDC = data{1};
% Control Commands- Speed
group_M5S = "Control commands";
channel_M5S = "M5 speed cmd [RPM]";
tdmsreadprop(fileName, "ChannelGroupName",group_M5S, "ChannelName", channel_M5S);
data = tdmsread(fileName, "ChannelGroupName",group_M5S, "ChannelName", channel_M5S);
M5S = data{1};
group_M6S = "Control commands";
channel_M6S = "M6 speed cmd [RPM]";
tdmsreadprop(fileName, "ChannelGroupName",group_M6S, "ChannelName", channel_M6S);
data = tdmsread(fileName, "ChannelGroupName",group_M6S, "ChannelName", channel_M6S);
M6S = data{1};
group_M7S = "Control commands";
channel_M7S = "M7 speed cmd [RPM]";
tdmsreadprop(fileName, "ChannelGroupName",group_M7S, "ChannelName", channel_M7S);
data = tdmsread(fileName, "ChannelGroupName",group_M7S, "ChannelName", channel_M7S);
M7S = data{1};
group_M8S = "Control commands";
channel_M8S = "M8 speed cmd [RPM]";
tdmsreadprop(fileName, "ChannelGroupName",group_M8S, "ChannelName", channel_M8S);
data = tdmsread(fileName, "ChannelGroupName",group_M8S, "ChannelName", channel_M8S);
M8S = data{1};
% Control Commands- Torque
group_M5T = "Control commands";
channel_M5T = "M5 torque cmd [Nm]";
tdmsreadprop(fileName, "ChannelGroupName",group_M5T, "ChannelName", channel_M5T);
data = tdmsread(fileName, "ChannelGroupName",group_M5T, "ChannelName", channel_M5T);
M5T = data{1};
group_M6T = "Control commands";
channel_M6T = "M6 torque cmd [Nm]";
tdmsreadprop(fileName, "ChannelGroupName",group_M6T, "ChannelName", channel_M6T);
data = tdmsread(fileName, "ChannelGroupName",group_M6T, "ChannelName", channel_M6T);
M6T = data{1};
group_M7T = "Control commands";
channel_M7T = "M7 torque cmd [Nm]";
tdmsreadprop(fileName, "ChannelGroupName",group_M7T, "ChannelName", channel_M7T);
data = tdmsread(fileName, "ChannelGroupName",group_M7T, "ChannelName", channel_M7T);
M7T = data{1};
group_M8T = "Control commands";
channel_M8T = "M8 torque cmd [Nm]";
tdmsreadprop(fileName, "ChannelGroupName",group_M8T, "ChannelName", channel_M8T);
data = tdmsread(fileName, "ChannelGroupName",group_M8T, "ChannelName", channel_M8T);
M8T = data{1};
%ARRAYS
N1 = table2array(N1);
N2 = table2array(N2);
N3 = table2array(N3);
N4 = table2array(N4);
N5 = table2array(N5);
N6 = table2array(N6);
N7 = table2array(N7);
N8 = table2array(N8);
T1 = table2array(T1);
T2 = table2array(T2);
T3 = table2array(T3);
T4 = table2array(T4);
T5 = table2array(T5);
T6 = table2array(T6);
T7 = table2array(T7);
T8 = table2array(T8);
I1a = table2array(I1a);
I2a = table2array(I2a);
I3a = table2array(I3a);
I4a = table2array(I4a);
I1b = table2array(I1b);
I2b = table2array(I2b);
I3b = table2array(I3b);
I4b = table2array(I4b);
I1c = table2array(I1c);
I2c = table2array(I2c);
I3c = table2array(I3c);
I4c = table2array(I4c);
IDC = table2array(IDC);
V1ab = table2array(V1ab);
V2ab = table2array(V2ab);
V3ab = table2array(V3ab);
V4ab = table2array(V4ab);
V1bc = table2array(V1bc);
V2bc = table2array(V2bc);
V3bc = table2array(V3bc);
V4bc = table2array(V4bc);
V1ca = table2array(V1ca);
V2ca = table2array(V2ca);
V3ca = table2array(V3ca);
V4ca = table2array(V4ca);
VDC= table2array(VDC);
M5S = table2array(M5S);
M6S = table2array(M6S);
M7S = table2array(M7S);
M8S = table2array(M8S);
M5T = table2array(M5T);
M6T = table2array(M6T);
M7T = table2array(M7T);
M8T = table2array(M8T);
% GRAPHS AND TIME STAMPS
minLength_1 = min([length(time), length(T1), length(I1a)]);
minLength_2 = min([length(time), length(T1), length(M5T)]);
time = time(1:minLength_1);
T5 = T5(1:minLength_1);
I1a = I1a(1:minLength_1);
M5T = M5T(1:minLength_2);
figure;
hold on;
subplot(2, 1, 1);
plot(time, T5, ‘r-‘, ‘DisplayName’, ‘T5 [Nm]’);
xlabel(‘Time (s)’);
ylabel(‘T5 [Nm]’);
title(‘T5 vs. Time’);
legend(‘show’);
subplot(2, 1, 2);
plot(time, M5T, ‘b-‘, ‘DisplayName’, ‘M5T [Nm]’);
xlabel(‘Time (s)’);
ylabel(‘M5T [Nm]’);
title(‘M5T vs. Time’);
legend(‘show’);
legend;
hold off;
[~, maxIdx] = max(T5);
maxTime = time(maxIdx);
zeroCrossIdx = find(T5(maxIdx:end) <= 0, 1, ‘first’) + maxIdx – 1;
if isempty(zeroCrossIdx)
timeToZero = NaN;
disp(‘Data does not return to zero after maximum.’);
else
timeToZero = time(zeroCrossIdx) – maxTime;
disp(timeToZero);
end
% Find the index where interpolated T5 matches M5
matchIndex = find(T5 == M5T);
if isempty(matchIndex)
disp(‘T5 does not match M5 ‘);
else
matchTime = commonTime(matchIndex);
fprintf(‘T5 matches M5 at t = %.2f seconds (interpolated).n’, matchTime);
end #tdms, #tdmsread MATLAB Answers — New Questions