所以我有一个.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变量。
试试这个-
%%// 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