In this case, the easiest way is to :
- import your experimental data as a table
- add a column that divides the dose amount in gram by the molecular weight
- convert the table to a groupedData object
- call the method createDoses on the groupedData object
With this approach the molecular weight won't be a parameter of the SimBiology model but will be a parameter defined in your script/function to run the fit instead.
There is a way to make this conversion happen automatically in the model itself but it is not trivial. What you suggested with the initial assignment + dose would not work unfortunately. Initial and repeated assignments are evaluated first to get the initial conditions and only then doses are applied. So your doseAmount parameter would remain zero.
The solution I came up with involves the use of events. This has the advantage of working fine even in the case of repeated doses within the same group.
I have attached a working example developed in R2021a in the SimBiology Apps. Please have a look at the program Program_events.
Edit: Please note that this example is for bolus dose only. It won't work if your dataset contains a rate column.
However, if you run the fit using a script, you don’t necessarily need to add those the events and extra species/parameters to the SimBiology project file. You can do it temporarily in the script. Here is the code you would need:
compObj = addcompartment(modelObj, "comp_temp",1,"Unit","liter");
eventFcn = ["comp.speciesMole = comp.speciesMole + comp_temp.speciesGram/molecularWeight";
"comp_temp.speciesGram = zeroGram"];
addevent(modelObj,"time > 0",eventFcn);
addevent(modelObj,"comp_temp.speciesGram > zeroGram",eventFcn);
I hope this helps.