Matrix column extraction not working when using codegen

1 回表示 (過去 30 日間)
John Edwards
John Edwards 2022 年 4 月 22 日
コメント済み: John Edwards 2022 年 4 月 25 日
I'm trying to integrate some Matlab code with some C code, using codegen. For this task I need to extract some columns of data from a Matlab matrix.
The Matlab code runs fine but the C code does not appear to be extracting the columns correctly.
For example, if I have:
a=[1 2 3; 4 5 6; 7 8 9];
and I perform the following:
a1 = a(:,1);
a2 = a(:,2);
disp(a1);
disp(a2);
Then I get the expected output:
1
4
7
2
5
8
However, if I run codegen (on a slightly larger set) the C code is:
memcpy(&a1[0], &a[0], 30U * sizeof(double));
memcpy(&a2[0], &a[30], 30U * sizeof(double));
which results in the ouput:
1
2
3
4
5
6
Note: My actual data is read in from a large .csv file so I have simplified the details above to show the problem.
Also, with the large data files, the generated C code is using for loops rather than memcpy but that's by the by because the results are still the same.
Any suggestions would be most welcome.
Thanks very much,
John

採用された回答

Mark McBroom
Mark McBroom 2022 年 4 月 25 日
  1 件のコメント
John Edwards
John Edwards 2022 年 4 月 25 日
Thank you very much for the quick response.
That worked great.
Best regards,
John

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMATLAB Coder についてさらに検索

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by