Dear all,
I have got a substring and an array which look like this
substr={'B0.2Si0.05'};numarray = [0.184320000000000 0.0460800000000000];
I want to replace the numbers in the substring (0.2, 0.5) in with the numbers from numarray. 0.2 should then become 0.18432 and 0.5 should become 0.04608 respectively. This seems pretty simply but I somehow fail to do it.
I have tried to do
newSubstr = regexprep(substr{1}, '(\d+)(?:\.(\d{1,2}))?', cellfun(@num2str, num2cell(numarray), 'uni', false));newSubstr = 1×1 cell array {'B0.046080.04608Si0.046080.04608'}
I also tried using cellstr, sprintfc, strrep but I didn't get what I want 🙁 e.g.
newSubstr = regexprep(substr{1},'(\d+)(?:\.(\d{1,2}))?', sprintfc('%f', numarray)) newSubstr = 1×1 cell array {'B0.0460800.046080Si0.0460800.046080'}
The solution has to be dynamic e.g. Substr can easily have more components and numarray will always grow with it. I'm sure that I'm missing something very basic here…
Cheers,
Lukas
Best Answer