String and array input from xlsx file

14 visualizaciones (últimos 30 días)
Jacob Rhodes
Jacob Rhodes el 6 de Jun. de 2023
Respondida: Abhishek Krishna el 3 de Jul. de 2023
Looking to directly input strings and arrays with corresponding time values for simulation from an excel spreadsheet. From what I can tell, the From Spreadsheet block only has the capability to take numerical data from spreadsheets. Is there a work around with the From Spreadsheet block or using another block that anyone is aware of? I've played around with using a matlab function to achieve such behavior, but no luck. Thanks in advance.

Respuestas (1)

Abhishek Krishna
Abhishek Krishna el 3 de Jul. de 2023
Hi,
Yes, you are right that the From Spreadsheet block in Simulink typically deals with numerical data. However, there are a few workarounds you can try to input strings and arrays with corresponding time values from an Excel spreadsheet.
  1. Convert strings to numerical values: If your strings can be represented as numerical values, you can convert them to numbers in Excel before importing the data into Simulink. For example, you can assign unique numerical values to each string and use those values in Simulink.
  2. Use a MATLAB Function block: Instead of using the From Spreadsheet block directly, you can try using a MATLAB Function block to read the data from the spreadsheet. Inside the MATLAB Function block, you can use MATLAB's built-in functions like xlsread or readtable to read the data from the Excel file, including strings and arrays with corresponding time values.
  3. Export as CSV: If the Excel spreadsheet contains only strings and arrays with corresponding time values, you can save it as a CSV (Comma-Separated Values) file. Simulink has a block called From Workspace that can read data from a CSV file. You can then use this block to import the data into your simulation.
Remember to ensure that the file path is correctly specified, and that the data is formatted appropriately for the method you choose.
I hope this helps!

Productos


Versión

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by