Name a dataset that will be used in Simulink

조회 수: 3 (최근 30일)
David Cole
David Cole 2024년 7월 14일
댓글: David Cole 2024년 7월 15일
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

채택된 답변

Paul
Paul 2024년 7월 15일
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.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

제품


릴리스

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by