Matrix column extraction not working when using codegen
2 views (last 30 days)
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);
Then I get the expected output:
However, if I run codegen (on a slightly larger set) the C code is:
memcpy(&a1, &a, 30U * sizeof(double));
memcpy(&a2, &a, 30U * sizeof(double));
which results in the ouput:
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,