I can't guarantee that the Import will work properly without having a sample ".m" file, but somewhere in my dim past, I've used MatLab, and I recall that ".m" files are simple text files. Therefore, we can do the following.
Suppose that the file in which you have stored
C_p_e = C_state/C_c;
C_p_f = I_state/I_i;
R_p_e = R_r*C_p_f;
I_p_e = (Se_p_e-R_p_e)-C_p_e;
is called temp.m. Then, we import the file as a String using
commands = Import["temp.m", "String"];
We then want to change the variable names that have underscores with the corresponding notation in MMA (which does not allow underscores in variable names). Here's one possibility. We first replace all capital letters by lower-case ones so as not to conflict with built-in MMA commands (for instance, both C and I are built-in protected symbols in MMA). Since you are using lower-case and upper-case versions of the same letter, I will do, for instance, cC in place of C:
comm1 = StringReplace[commands, {"\n\n" :> "\n", a_?UpperCaseQ :> ToLowerCase[a] <> a}]
(* cC_p_e:=cC_state/cC_c;
cC_p_f:=iI_state/iI_i;
rR_p_e:=rR_r*cC_p_f;
iI_p_e:=(sSe_p_e-rR_p_e)-cC_p_e; *)
(I have also gotten rid of the extra lines in between expressions for convenience.)
Next, we turn the underscores into brackets (in some sense):
comm2 = StringReplace[comm1
, {"_" ~~ pat1 : LetterCharacter .. ~~ "_" ~~ pat2 : LetterCharacter .. :> "[" <> pat1 <> "," <> pat2 <> "]"
, "_" ~~ pat : LetterCharacter .. :> "[" <> pat <> "]"}]
(* cC[p,e]=cC[state]/cC[c];
cC[p,f]=iI[state]/iI[i];
rR[p,e]=rR[r]*cC[p,f];
iI[p,e]=(sSe[p,e]-rR[p,e])-cC[p,e]; *)
Finally, we evaluate this using
comm2 // ToExpression;
You will find, upon testing ?cC that cC[p,e] has been set to cC[state]/cC[c] and cC[p,f] has been set to iI[state]/iI[i].
Now, if you want to make MMA equations, modify the above with the following.
(1) Add "=" -> "==" to the first list of StringReplace replacements.
(2) After the rest has been executed, do
list = StringSplit[comm2, ";"];
Scan[(eqn[#] = ToExpression @ list[[#]]) &, Range@Length@list];
This will assign the equation cC[p,f]==iI[state]/iI[i] to eqn[2], for instance.
ToExpression. See edited answer (fix is at end). – march Aug 25 '15 at 20:07listis still aListofStrings. You can't useReplaceonStrings. Either useStringReplaceon each element inlistor do the replacement after you do theScan. As it is, I think if you go through and understand what all the command in the answer are doing, you will be able to fix the problem on your own. – march Aug 25 '15 at 20:51RuleDelayedis just habit sometimes. It doesn't matter there."\n"is the character that stands for "end-of-line". So any time a new line begins, MMA sees it as "\n". I'm just replacing two of them (there is an extra space between lines) with one. – march Aug 26 '15 at 15:07"C_state" -> "Int[v[t],t]"}] Do you have an idea why the 2nd line doesn't work ? @march
– Bendesarts Aug 26 '15 at 15:50