MATLAB Answers

How to apply function "strrep" to multiple substrings

9 views (last 30 days)
Hi there,
It would be my great pleasure if anyone could assist me with the following error, caused after I applied strrep:
newIDFFile = strrep(readIDFFile, {'@@P1@@', num2str(u_gen_s)}, {'@@P2@@', num2str(u_gen_w)}, {'@@P3@@', num2str(u_gen_e)}, {'@@P4@@', num2str(u_gen_n)});
Also, I tried the following format:
newIDFFile = strrep(readIDFFile, '@@P1@@', num2str(u_gen_s), '@@P2@@', num2str(u_gen_w), '@@P3@@', num2str(u_gen_e), '@@P4@@', num2str(u_gen_n));
while the error message is:
Error using strrep
Too many input arguments.

Accepted Answer

Bruno Luong
Bruno Luong on 2 Sep 2020
newIDFFile = ...
strrep( ...
strrep( ...
strrep(readIDFFile, ...
'@@P1@@', num2str(u_gen_s)), ...
'@@P2@@', num2str(u_gen_w)), ...
'@@P3@@', num2str(u_gen_e)), ...
'@@P4@@', num2str(u_gen_n));
Mohammad Dabbagh
Mohammad Dabbagh on 15 Oct 2020
It would be also my great pleasure if you could help me with the same question, while I need to write strrep for more than 32 substrings. It shows me the following error:
Error using objective (line 2)
Error: File: building_model.m Line: 260 Column: 11
Nesting of {, [, and ( cannot exceed a depth of 32.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!