New to simulink, how do I import data from a CSV to be used in a simulation?

조회 수: 50 (최근 30일)
David
David 2023년 7월 12일
댓글: Daniel 2023년 7월 13일
I have a couple columns of data that I want to be used in my simulation, each one is 32 rows long.
I tried to use the data inspector to import the CSV data, but I get an error where it tells me that the time values are not increasing monotonically. And that would be correct, because they are not time values. The data I'm trying to use in my simulation is increasing and decreasing.
Specifically the orange and blue lines in this picture
I guess I'm not supposed to use the data inspector to get this data into my simulation. What should I be doing/using? Thanks
  댓글 수: 1
Angelo Yeo
Angelo Yeo 2023년 7월 13일
Does the data have time information? If not, how are you going to use the data for simulation?

댓글을 달려면 로그인하십시오.

답변 (1개)

Daniel
Daniel 2023년 7월 13일
The issue you're running into is that Simulink can't import data without knowing the timebase for it. Every input entry has to get tagged with a time before Simulink can use it.
There are several ways to do this. For instance:
1) If you're importing Excel or CSV data directly into Simulink, the data must include time as the first column. If you use a From Spreadsheet block to import the data, you'll just need to create a column at the left with time values.
2) If modifying the spreadsheet isn't an option, you can read the data into MATLAB using readtable, convert the table output to an array with table2array, add time values as the first column, and import that data into Simulink using Data Import/Export or the From Workspace block.
I can provide more information on either. The first option would be a little simpler if you have the ability to modify the spreadsheet data, but either way should work reliably once it's set up properly.
  댓글 수: 3
David
David 2023년 7월 13일
I guess I'm having trouble figuring out how to extract the different columns from this from spreadsheet block. I want to feed each column (except for time) into different areas of my simulation. I'm trying to find a tutorial as we speak but figured I'd also put it here
Daniel
Daniel 2023년 7월 13일
It looks like once the block can handle the data, you should just get as many outputs from the block as you have data columns in the data. Then you can route each output to a different place as desired. Could you attach a screenshot of what you're seeing?

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 View and Analyze Simulation Results에 대해 자세히 알아보기

제품


릴리스

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by