所以我将.h文件定义为此
#ifndef CONSTANTS_H
#define CONSTANTS_H
#include "math.h"
//CALA = CA/LA, CRLR = CR/LR
#define CALA 0.2
#define CRLR 25.0
//self-propulsion and friction
#define ALPHA .15
#define BETA .05
//Evolution simulation size
#define STUDYSIZE 100
#define STUDYLENGTH 1
.....
#define INITIAL_CONDITION true
#endif
有没有办法导入我在这里定义的常量并将它们变成matlab变量。
答案 0 :(得分:0)
试试这个 -
%%// Read in data
imp_data = importdata(CPP_H_FILE,'\n');
%%// Remove the leading and trailing whitespaces
imp_data = cellstr(strtrim(char(imp_data)));
%%// Split into strings
split1 = regexp(imp_data,'\s','Split');
%%// Process to evaluate the variables into MATLAB
for k = 1:size(split1,1)
if strcmp(char(split1{k,1}(:,1)),'#define') && numel(split1{k,1})>2
val_str = strtok(char(split1{k,1}(:,end)), '/');
evalstr = strcat(char(split1{k,1}(:,2)),'=',val_str);
evalc(evalstr);
end
end