Name a dataset that will be used in Simulink

1 view (last 30 days)
How do I name a dataset. My dataset is available in Simulink; however, it is identified as unnamed. I want to use multiple datasets so I need to be able to identify each of them separately.
clc
% Parameters
f0 = 60; % Fundamental frequency in Hz
sampling_rate = 120000; % Sampling rate in Hz
stopTime = 0.1; % Duration of the signal in seconds
t = 0:1/sampling_rate:stopTime; % Time vector
% Harmonic amplitudes (example values)
IA = [771.32, 0.24,1.36, 0.96, 6.64, 0.16, 2.36, 0, 0.48,...
0.16, 1.84, 0.08, 0.56, 0.08, 0.32, 0.08, 0.24,...
0.08, 0.08, 0.08, 0.08, 0, 0.48, 0, 0.16, 0.08, 0.08, 0, 0.08, 0, 0, 0, 0,...
0.08, 0.24, 0.16, 0.32, 0.08, 0.08, 0.08, 0.32,...
0.08, 0.24, 0.16, 0.24, 0.08, 0.8, 0.16, 0.48,...
0.16, 0.16, 0.08, 0.72, 0.24, 0.72, 0.16, 0.24,...
0.08, 0.16, 0.08, 0.56, 0.08, 0.32]'; % Amplitudes for the 1st, 2nd, and 3rd harmonics
IB = [773.44, 0.4, 0.72, 0.88, 6.16, 0.4, 2.84, 0.08, 0.4, 0.08,...
1.76, 0.08, 0.96, 0.08, 0.16, 0, 0.4, 0.08, ...
0.24, 0.08, 0, 0, 0.4, 0, 0.24, 0,...
0.08, 0, 0.08, 0, 0.08, 0, 0.16, 0.08,...
0.16, 0.08, 0.32, 0.08, 0.08, 0, 0.24, 0.08,...
0.4, 0.08, 0.08, 0.08, 0.8, 0.08, 0.72, 0.16,...
0.08, 0.32, 0.48, 0, 0.08, 0.08, 0.24, 0.32,...
0.24, 0.24, 0.72, 0.24, 0.08];
IC = [775.76, 0.24, 0.56, 0.72, 6.48, 0.24, 2.44, 0.08, 0.08, 0.08, ...
2.12, 0, 0.72, 0.08, 0.16, 0.08,...
0.32, 0, 0.08, 0, 0, 0, 0.56, 0, 0.08, 0, 0.08, 0, ...
0, 0, 0.08, 0, 0, 0, 0.24, 0, 0.24, 0, 0, 0.08, 0.24, 0, 0.32, 0,...
0.08, 0.08, 0.8, 0.08, 0.56, 0.08, 0.32, 0.08,...
0.64, 0.32, 0.56, 0.08, 0.24, 0.32, 0.24, 0.32, 0.72, 0.16, 0.24];
%% Generate the current
currentIA = zeros(size(t));
currentIB = zeros(size(t));
currentIC = zeros(size(t));
for n = 1:length(IA)
amplitudeIA = IA(n);
currentIA = currentIA + amplitudeIA * cos(2 * pi * n * f0 * t);
amplitudeIB = IB(n);
currentIB = currentIB + amplitudeIB * cos(2 * pi * n * f0 * t + 2*pi/3);
amplitudeIC = IC(n);
currentIC = currentIC + amplitudeIC * cos(2 * pi * n * f0 * t - 2*pi/3);
end
currents = timeseries([currentIA; currentIB; currentIC]', t);
dataset = Simulink.SimulationData.Dataset(currents); %How do I give the dataset a name?
save currentsWith63Harmonics.mat dataset
%% Plot the signal
figure(1);
plot(t, currentIA);
hold on
plot(t, currentIB);
plot(t, currentIC);
title('Three-Phase currents with 63 harmonics');
xlabel('Time (s)');
ylabel('A');
grid on;
figure(2);
ee_calculateThdPercent(1:1:63,IA')
bar(1:1:63,IA')
clear IA IB IC f0 duration amplitudeIA amplitudeIB amplitudeIC
clear n t signal

Accepted Answer

Paul
Paul on 15 Jul 2024
Hi David,
The 'unnamed' in that block is the name of the signal, not the dataset.
f0 = 60; % Fundamental frequency in Hz
sampling_rate = 120000; % Sampling rate in Hz
stopTime = 0.1; % Duration of the signal in seconds
t = 0:1/sampling_rate:stopTime; % Time vector
% Harmonic amplitudes (example values)
IA = [771.32, 0.24,1.36, 0.96, 6.64, 0.16, 2.36, 0, 0.48,...
0.16, 1.84, 0.08, 0.56, 0.08, 0.32, 0.08, 0.24,...
0.08, 0.08, 0.08, 0.08, 0, 0.48, 0, 0.16, 0.08, 0.08, 0, 0.08, 0, 0, 0, 0,...
0.08, 0.24, 0.16, 0.32, 0.08, 0.08, 0.08, 0.32,...
0.08, 0.24, 0.16, 0.24, 0.08, 0.8, 0.16, 0.48,...
0.16, 0.16, 0.08, 0.72, 0.24, 0.72, 0.16, 0.24,...
0.08, 0.16, 0.08, 0.56, 0.08, 0.32]'; % Amplitudes for the 1st, 2nd, and 3rd harmonics
IB = [773.44, 0.4, 0.72, 0.88, 6.16, 0.4, 2.84, 0.08, 0.4, 0.08,...
1.76, 0.08, 0.96, 0.08, 0.16, 0, 0.4, 0.08, ...
0.24, 0.08, 0, 0, 0.4, 0, 0.24, 0,...
0.08, 0, 0.08, 0, 0.08, 0, 0.16, 0.08,...
0.16, 0.08, 0.32, 0.08, 0.08, 0, 0.24, 0.08,...
0.4, 0.08, 0.08, 0.08, 0.8, 0.08, 0.72, 0.16,...
0.08, 0.32, 0.48, 0, 0.08, 0.08, 0.24, 0.32,...
0.24, 0.24, 0.72, 0.24, 0.08];
IC = [775.76, 0.24, 0.56, 0.72, 6.48, 0.24, 2.44, 0.08, 0.08, 0.08, ...
2.12, 0, 0.72, 0.08, 0.16, 0.08,...
0.32, 0, 0.08, 0, 0, 0, 0.56, 0, 0.08, 0, 0.08, 0, ...
0, 0, 0.08, 0, 0, 0, 0.24, 0, 0.24, 0, 0, 0.08, 0.24, 0, 0.32, 0,...
0.08, 0.08, 0.8, 0.08, 0.56, 0.08, 0.32, 0.08,...
0.64, 0.32, 0.56, 0.08, 0.24, 0.32, 0.24, 0.32, 0.72, 0.16, 0.24];
%% Generate the current
currentIA = zeros(size(t));
currentIB = zeros(size(t));
currentIC = zeros(size(t));
for n = 1:length(IA)
amplitudeIA = IA(n);
currentIA = currentIA + amplitudeIA * cos(2 * pi * n * f0 * t);
amplitudeIB = IB(n);
currentIB = currentIB + amplitudeIB * cos(2 * pi * n * f0 * t + 2*pi/3);
amplitudeIC = IC(n);
currentIC = currentIC + amplitudeIC * cos(2 * pi * n * f0 * t - 2*pi/3);
end
currents = timeseries([currentIA; currentIB; currentIC]', t);
dataset = Simulink.SimulationData.Dataset(currents); %How do I give the dataset a name?
Looking at dataset
dataset
dataset =
Simulink.SimulationData.Dataset 'currents' with 1 element Name BlockPath _______ _________ 1 [1x1 Signal] unnamed '' - Use braces { } to access, modify, or add elements using index.
we see that it does have a name 'currents', which I guess it was given automatically based in the variable name in its constructor. The dataset name can be changed if you want. But the issue you're seeing is that the signal inside the dataset is unnamed. You can change that when currents is created
currents = timeseries([currentIA; currentIB; currentIC]', t,'Name','allcurrents');
dataset = Simulink.SimulationData.Dataset(currents)
dataset =
Simulink.SimulationData.Dataset 'currents' with 1 element Name BlockPath ___________ _________ 1 [1x1 Signal] allcurrents '' - Use braces { } to access, modify, or add elements using index.
Now the outuput from the Signal Editor block will be 'allcurrents'.
You can also operate on dataset directly to assign a name to that signal.
dataset{1}.Name = 'thecurrents'
dataset =
Simulink.SimulationData.Dataset 'currents' with 1 element Name BlockPath ___________ _________ 1 [1x1 Signal] thecurrents '' - Use braces { } to access, modify, or add elements using index.

More Answers (0)

Categories

Find more on Programming in Help Center and File Exchange

Products


Release

R2024a

Community Treasure Hunt

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

Start Hunting!