Clear Filters
Clear Filters

How can i load data from workspace to simulink

1 view (last 30 days)
Hallo,
I am trying to export a Excel-file to Simulink. So, I download the table in Matlab / workspace. So I created a variable through this code
"resultsFile = 'example.xlsx';
example2019 = readtable(resultsFile);".
the code create a variable in the workspace.
this variable is in a table format. afterthat, i convert this table to struct.
when i use the block 'from workspace' i get an error message "invalid structure-format variable specified as workspace input in 'untitled/From Workspace'. The input structure must be scalar.",
in the example you can see a little part from my data in the table, because my orginal table contain 35041row and 2 column .
how can i solve this problem, please?

Answers (2)

Ameer Hamza
Ameer Hamza on 7 Mar 2020
An easy way is to import the data as a numeric array instead of structure or time series. The numeric array is imported using constant block. Check the example in the attached Simulink file.
First run these lines
resultsFile = 'example.xlsx';
example2019 = readtable(resultsFile);
power = example2019.Power_KW_;
and then run the simulink model. The simulink model will iterate through all the values in power array.
The .mdl file is also attached in case there is a compatability issue between versions of Simulink.

Anas Alahdab
Anas Alahdab on 1 Apr 2020
Thank you

Categories

Find more on Modeling in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!