- Author:
- WeiweiAi <wai484@aucklanduni.ac.nz>
- Date:
- 2022-06-28 15:54:52+12:00
- Desc:
- Add Markov states
- Permanent Source URI:
- https://models.cellml.org/workspace/6bc/rawfile/6dc0ec3b88004d6d2aff5ddf20061aa3cb35d7da/Scripts/writePara.m
function writePara(comp,idx,csvfile)
vars=extractfield(comp,'vars');
all_vars=[];
for i=1: length(vars)
all_vars=[all_vars;vars{1,i}];
end
% Get all non-duplicate parameters
indexp=all_vars(:,idx.vctg)=="para";
pvars=all_vars(indexp,:);
[~,ip,~]=unique(pvars(:,idx.var)','stable');
comp_para.name='Para';
comp_para.children='';
vars_para=pvars(ip,:);
values=vars_para(:,idx.val);
units=vars_para(:,idx.unit);
% Write to csv for docmentation
old = "_";
new = "_{";
str = vars_para(:,idx.var);
pat_1 = alphanumericsPattern + "_" + alphanumericsPattern; % assume there is no a_b_c pattern
idx_1= matches(str,pat_1);
str(idx_1) = "$"+replace(str(idx_1),old,new)+"}"+"$";
str(~idx_1) = "$"+str(~idx_1)+"$";
old = "_per_";
new = "/";
units = replace(units,old,new);
old = "per_";
new = "/";
units = replace(units,old,new);
old = "/";
new = "/(";
pat_1 = alphanumericsPattern+"/" + alphanumericsPattern+"_"+alphanumericsPattern;
idx_1= matches(units,pat_1);
pat_2 = "/" + alphanumericsPattern+"_"+alphanumericsPattern;
idx_2= matches(units,pat_2);
units(idx_1|idx_2) =replace(units(idx_1|idx_2),old,new)+")";
old = "_";
new = "\cdot";
units = "$"+replace(units,old,new)+"$";
M(1,:)=cellstr(str');
M(2,:)=cellstr(units');
M(3,:)=cellstr(values');
writecell(M,csvfile,'Delimiter',',')
M={};
M(:,1)=cellstr(str);
M(:,2)=cellstr(units);
M(:,3)=cellstr(values);
[filepath,~,~] = fileparts(csvfile);
paraCsv=[filepath filesep 'Para_v.csv'];
writecell(M,paraCsv,'Delimiter',',')
end