Is there any command for .xlsx file to import directly to Signal Builder.

5 vues (au cours des 30 derniers jours)
Shweta Majagi
Shweta Majagi le 17 Oct 2023
Réponse apportée : Shlok le 11 Sep 2024
  1. I have some inputs recived from user in .xlsx file need to import it into Signal Builder using commands. It can be done manually but i need it with commands which can be done automatically.
Steps:
a. xlsx file needs to be imported from other folders of Desktop.
b. While importing .xlsx file which needs path.
c. Then it should select sheets and replace existing data--> apply --> ok.

Réponses (1)

Shlok
Shlok le 11 Sep 2024
Hi Shweta,
The Signal Builder block is outdated and no longer available in the latest version of Simulink. Hence, I would suggest the following steps to migrate to Signal Editor block, and then import the data using the script. To achieve the same, follow these steps:
1. Start by reading the data from the XLSX file, extracting both the time and signal values (for each signal) into separate variables.
filepath = 'dummySignalData.xlsx'; % Example dataset with columns "Time", "Signal1", "Signal2"
data = readtable(filepath);
time = data{:, 'Time'}; % Time vector
signal1 = data{:, 'Signal1'}; % Signal1 data
signal2 = data{:, 'Signal2'}; % Signal2 data
2. Using the extracted time and signal data, create timeseries objects that represent each signal over the time vector.
ts1 = timeseries(signal1, time, 'Name', 'Signal1');
ts2 = timeseries(signal2, time, 'Name', 'Signal2');
3. Create a Simulink.SimulationData.Dataset object and add the timeseries objects into it. This dataset will hold the signals for the simulation.
dataset = Simulink.SimulationData.Dataset;
dataset = dataset.addElement(ts1);
dataset = dataset.addElement(ts2);
4. Save the dataset to a MAT file. This file will later be used to load the signal data into the Signal Editor block.
excelToMatFile = 'dummySignalData.mat';
save(excelToMatFile, 'dataset');
5. Open your Simulink model and replace the existing Signal Builder block with a Signal Editor block using the appropriate function for migration.
model = 'myModel'; % Example model
open_system(model);
block = [model '/mySignalBuilder']; % Assuming the "Signal Builder" block is named "mySignalBuilder" in "myModel"
signalBuilderToSignalEditor(block, 'Replace', true);
6. Once the Signal Editor block is in place, load the MAT file containing the signal data into it.
set_param(block, 'FileName', excelToMatFile);
7. After importing the data, save the model with the new Signal Editor block and close it.
save_system(model);
close_system(model);
These steps will allow you to successfully transition to the Signal Editor block while importing signals from an Excel file into your Simulink model.
Note: Upon migration, a dataset.mat file will be created. If you wish to rerun the script, you'll need to delete this file manually.
To know more about “Signal Editor” block, refer to the following documentation link:
Hope this helps!

Catégories

En savoir plus sur Modeling dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by