codegen error: Conversion to struct from double is not possible

10 Ansichten (letzte 30 Tage)
I am trying to convert Matlab legacy code into a C program. I went though the usual flows, but am having a build error that I do not understand:
Nfft = 8;
[~,coh] = size(h); // h = array of 168 elements;
display(coh); // displays 168
if mod(coh,Nfft)~=0,
h1 = [h zeros(1,Nfft-mod(coh,Nfft))];
else
h1 = h;
end
This works as expected in Matlab. But when I run it through codegen (after removing the display), I get an error at the line h1 = [h zeros(1,Nfft-mod(coh,Nfft))]; with the error message:
Conversion to struct from double is not possible.
I realize that in the matlab code, it doesn't go through this part of the code. (since 168%8 == 0).
Any ideas how to fix this?
EDIT: After some investigating, I realize that I am reading in h from a .mat file and this may be the reason. Is data read in from a .mat file considered to be a structure? If this is the case, then maybe I need to convert each element to a double first? Seems kind of hacky..

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 8 Mär. 2017
"Is data read in from a .mat file considered to be a structure?"
If you used
h = load('YourFile.mat')
then h would be a structure, containing one field for each variable that you loaded from the .mat file. If the only thing in that .mat file was a variable named 'h' then you would then address it as h.h
The general method to use is something like
filestruct = load('YourFile.mat'); %load into a structure
h = filestruct.h; %pull out a specific part of the structure.
  1 Kommentar
ChipMonk
ChipMonk am 8 Mär. 2017
Yes this works! I was using:
h = coder.load('my_file.mat', 'my_file_var1');
Changed it to:
tmp = coder.load('my_file.mat');
h = tmp.my_file_var1;
Thank you@!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by