フィルターのクリア

Read excel data in Simulink and convert it into an array

5 ビュー (過去 30 日間)
Aniruddh Dalvi
Aniruddh Dalvi 2024 年 5 月 19 日
編集済み: Paul 2024 年 5 月 19 日
I am trying to import data from an excel sheet as an array into Simulink and turn it into an array. I doing it using a matlab function
the function is written as
function data = dataserial(file,range)
%#codegen
data = readmatrix(file,'Sheet1',range);
I am getting the following error:
Function 'readmatrix' not supported for code generation.
I tried looking this up but I am still a bit uncertain on the excact solution.
I just wanted to enquire if anyone has done the same: Importing excel data as an array
Also, I have tried the "From Spreadsheet" block in simulink but it was not working as well

回答 (2 件)

Abhishek Kumar Singh
Abhishek Kumar Singh 2024 年 5 月 19 日
Hi Aniruddh,
It appears you're using the %#codegen directive, which serves as a pragma to indicate your intention for code generation from a MATLAB algorithm. Removing this line should eliminate the error you're encountering.
However, if your workflow requires code generation, it might be beneficial to consider using the "From Spreadsheet" block instead. For a clearer understanding of its functionality and to get the most out of it, I highly recommend consulting the documentation and exploring the provided examples. You can find more information here: From Spreadsheet Documentation.
I hope this helps!

Paul
Paul 2024 年 5 月 19 日
編集済み: Paul 2024 年 5 月 19 日
Add the line
coder.extrinsic('readmatrix');
at the top of the Matlab Function after the %#codegen directive.
Or, read in the matrix outside of the block diagram, perhaps in a callback or in the command window (for example, the best solution would depend on what the workflow actually is), and then use the matrix as a block parameter in a Constant block (or other appropriate block).

カテゴリ

Help Center および File ExchangeData Import from MATLAB についてさらに検索

製品


リリース

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by