How to apply function "strrep" to more than 32 substrings?

Hi there,
It would be my great pleasure if anyone could assist me with the following error, caused after I applied strrep to more than 32 substrings:
newIDFFile = ...
strrep( ...
strrep( ...
strrep( ...
strrep( ...
strrep( ...
strrep( ...
strrep( ...
strrep( ...
strrep( ...
strrep( ...
strrep( ...
strrep( ...
strrep( ...
strrep( ...
strrep( ...
strrep( ...
strrep( ...
strrep( ...
strrep( ...
strrep( ...
strrep( ...
strrep( ...
strrep( ...
strrep( ...
strrep( ...
strrep( ...
strrep( ...
strrep( ...
strrep( ...
strrep( ...
strrep(...
strrep( ...
strrep( ...
strrep( ...
strrep( ...
strrep( ...
strrep( ...
strrep( ...
strrep( ...
strrep( ...
strrep( ...
strrep( ...
strrep( ...
strrep( ...
strrep( ...
strrep( ...
strrep( ...
strrep( ...
strrep( ...
strrep( ...
strrep( ...
strrep( ...
strrep( ...
strrep( ...
strrep( ...
strrep( ...
strrep( ...
strrep( ...
strrep( ...
strrep( ...
strrep( ...
strrep( ...
strrep( ...
strrep( ...
strrep( ...
strrep( ...
strrep( ...
strrep( ...
strrep( ...
strrep( ...
strrep( ...
strrep( ...
strrep( ...
strrep( ...
strrep( ...
strrep( ...
strrep(...
strrep( ...
strrep( ...
strrep(...
strrep( ...
strrep( ...
strrep( ...
strrep( ...
strrep( ...
strrep( ...
strrep( ...
strrep( ...
strrep( ...
strrep( ...
strrep( ...
strrep( ...
strrep( ...
strrep( ...
strrep( ...
strrep(readIDFFile, ...
'@@P1@@', (x(1))), ...
'@@P2@@', (x(2))), ...
'@@P3@@', (x(3))), ...
'@@P4@@', (x(4))), ...
'@@P5@@', (x(5))), ...
'@@P6@@', (x(6))), ...
'@@P7@@', (x(7))), ...
'@@P8@@', (x(8))), ...
'@@P9@@', (x(9))), ...
'@@P10@@', (x(10))), ...
'@@P11@@', (x(11))), ...
'@@P12@@', (x(12))), ...
'@@P13@@', (x(13))), ...
'@@P14@@', (x(14))), ...
'@@P15@@', (x(15))), ...
'@@P16@@', (x(16))), ...
'@@P17@@', (x(17))), ...
'@@P18@@', (x(18))), ...
'@@P19@@', (x(19))), ...
'@@P20@@', (x(20))), ...
'@@P21@@', (x(21))), ...
'@@P22@@', (x(22))), ...
'@@P23@@', (x(23))), ...
'@@P24@@', (x(24))), ...
'@@P25@@', (x(25))), ...
'@@P26@@', (x(26))), ...
'@@P27@@', (x(27))), ...
'@@P28@@', (x(28))), ...
'@@P29@@', (x(29))), ...
'@@P30@@', (x(30))), ...
'@@P31@@', (x(31))), ...
'@@P32@@', (x(32))), ...
'@@P33@@', (x(33))), ...
'@@P34@@', (x(34))), ...
'@@P35@@', (x(35))), ...
'@@P36@@', (x(36))), ...
'@@P37@@', (x(37))), ...
'@@P38@@', (x(38))), ...
'@@P39@@', (x(39))), ...
'@@P40@@', (x(40))), ...
'@@P41@@', (x(41))), ...
'@@P42@@', (x(42))), ...
'@@P43@@', (x(43))), ...
'@@P44@@', (x(44))), ...
'@@P45@@', (x(45))), ...
'@@P46@@', (x(46))), ...
'@@P47@@', (x(47))), ...
'@@P48@@', (x(48))), ...
'@@P49@@', (x(49))), ...
'@@P50@@', (x(50))), ...
'@@P51@@', (x(51))), ...
'@@P52@@', (x(52))), ...
'@@P53@@', (x(53))), ...
'@@P54@@', (x(54))), ...
'@@P55@@', (x(55))), ...
'@@P56@@', (x(56))), ...
'@@P57@@', (x(57))), ...
'@@P58@@', (x(58))), ...
'@@P59@@', (x(59))), ...
'@@P60@@', (x(60))), ...
'@@P61@@', (x(61))), ...
'@@P62@@', (x(62))), ...
'@@P63@@', (x(63))), ...
'@@P64@@', (x(64))), ...
'@@P65@@', (x(65))), ...
'@@P66@@', (x(66))), ...
'@@P67@@', (x(67))), ...
'@@P68@@', (x(68))), ...
'@@P69@@', (x(69))), ...
'@@P70@@', (x(70))), ...
'@@P71@@', (x(71))), ...
'@@P72@@', (x(72))), ...
'@@P73@@', (x(73))), ...
'@@P74@@', (x(74))), ...
'@@P75@@', (x(75))), ...
'@@P76@@', (x(76))), ...
'@@P77@@', (x(77))), ...
'@@P78@@', (x(78))), ...
'@@P79@@', (x(79))), ...
'@@P80@@', (x(80))), ...
'@@P81@@', (x(81))), ...
'@@P82@@', (x(82))), ...
'@@P83@@', (x(83))), ...
'@@P84@@', (x(84))), ...
'@@P85@@', (x(85))), ...
'@@P86@@', (x(86))), ...
'@@P87@@', (x(87))), ...
'@@P88@@', (x(88))), ...
'@@P89@@', (x(89))), ...
'@@P90@@', (x(90))), ...
'@@P91@@', (x(91))), ...
'@@P92@@', (x(92))), ...
'@@P93@@', (x(93))), ...
'@@P94@@', (x(94))), ...
'@@P95@@', (x(95))), ...
'@@P96@@', (x(96)));
Thanks!

댓글 수: 1

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.

댓글을 달려면 로그인하십시오.

 채택된 답변

Walter Roberson
Walter Roberson 2020년 10월 17일
편집: Walter Roberson 2020년 10월 18일
If you make x a string array with 96 or more elements, then the entire code can be replaced with
%{
newIDFFile = regexprep(readIDFFile, '@@P(\d+)@@', '${x{str2double($1)}}')
%}
For example,
x = "Here!"+(1:96);
readIDFFile = 'hello @@P3@@, how are you? @@P48@@ says hi!';
newIDFFile = regexprep(readIDFFile, '@@P(\d+)@@', '${x{str2double($1)}}')
newIDFFile = 'hello Here!3, how are you? Here!48 says hi!'

댓글 수: 9

This code would also work with x being a cell array of character vectors
Correction, the str2double is needed like in my example code. (The interface I am using at the moment makes it tricky for me to edit the code)
Hi @Walter Roberson,
Thank you so much for getting back to me. The "regexprep" worked properly. However, one more quick help would be highly apprecitaed! The story is that by using your approach, I'm receiving just numbers for that "newIDFFile". However, I need to receive one of the followings for "newIDFFile: R1WinConstruction, R2WinConstructio, R3WinConstruction, or R4WinConsruction. More detailed, my initial "x" is a string, as follows:
x = string(x);
for i = 1:24
if x(i) == "1"
x(i)= "set WinS_Construct = R1WinConstruction";
elseif x(i)== "2"
x(i)= "set WinS_Construct = R1WinConstruction";
elseif x(i)== "3"
x(i)= "set WinS_Construct = R1WinConstruction";
elseif x(i)== "4"
x(i)= "set WinS_Construct = R1WinConstruction";
elseif x(i)== "5"
x(i)= "set WinS_Construct = R1WinConstruction";
elseif x(i)== "6"
x(i)= "set WinS_Construct = R1WinConstruction";
elseif x(i)== "7"
x(i)= "set WinS_Construct = R1WinConstruction";
elseif x(i)== "8"
x(i)= "set WinS_Construct = R1WinConstruction";
elseif x(i)== "9"
x(i)= "set WinS_Construct = R1WinConstruction";
elseif x(i)== "10"
x(i)= "set WinS_Construct = R1WinConstruction";
elseif x(i)== "11"
x(i)= "set WinS_Construct = R1WinConstruction";
elseif x(i)== "12"
x(i)= "set WinS_Construct = R1WinConstruction";
elseif x(i)== "13"
x(i)= "set WinS_Construct = R1WinConstruction";
elseif x(i)== "14"
x(i)= "set WinS_Construct = R1WinConstruction";
elseif x(i)== "15"
x(i)= "set WinS_Construct = R1WinConstruction";
elseif x(i)== "16"
x(i)= "set WinS_Construct = R1WinConstruction";
elseif x(i)== "17"
x(i)= "set WinS_Construct = R1WinConstruction";
elseif x(i)== "18"
x(i)= "set WinS_Construct = R1WinConstruction";
elseif x(i)== "19"
x(i)= "set WinS_Construct = R1WinConstruction";
elseif x(i)== "20"
x(i)= "set WinS_Construct = R1WinConstruction";
elseif x(i)== "21"
x(i)= "set WinS_Construct = R1WinConstruction";
elseif x(i)== "22"
x(i)= "set WinS_Construct = R1WinConstruction";
elseif x(i)== "23"
x(i)= "set WinS_Construct = R1WinConstruction";
elseif x(i)== "24"
x(i)= "set WinS_Construct = R1WinConstruction";
end
end
for i = 25:48
if x(i) == "25"
x(i)= "set WinE_Construct = R1WinConstruction";
elseif x(i)== "26"
x(i)= "set WinE_Construct = R1WinConstruction";
elseif x(i)== "27"
x(i)= "set WinE_Construct = R1WinConstruction";
elseif x(i)== "28"
x(i)= "set WinE_Construct = R1WinConstruction";
elseif x(i)== "29"
x(i)= "set WinE_Construct = R1WinConstruction";
elseif x(i)== "30"
x(i)= "set WinE_Construct = R1WinConstruction";
elseif x(i)== "31"
x(i)= "set WinE_Construct = R1WinConstruction";
elseif x(i)== "32"
x(i)= "set WinE_Construct = R1WinConstruction";
elseif x(i)== "33"
x(i)= "set WinE_Construct = R1WinConstruction";
elseif x(i)== "34"
x(i)= "set WinE_Construct = R1WinConstruction";
elseif x(i)== "35"
x(i)= "set WinE_Construct = R1WinConstruction";
elseif x(i)== "36"
x(i)= "set WinE_Construct = R1WinConstruction";
elseif x(i)== "37"
x(i)= "set WinE_Construct = R1WinConstruction";
elseif x(i)== "38"
x(i)= "set WinE_Construct = R1WinConstruction";
elseif x(i)== "39"
x(i)= "set WinE_Construct = R1WinConstruction";
elseif x(i)== "40"
x(i)= "set WinE_Construct = R1WinConstruction";
elseif x(i)== "41"
x(i)= "set WinE_Construct = R1WinConstruction";
elseif x(i)== "42"
x(i)= "set WinE_Construct = R1WinConstruction";
elseif x(i)== "43"
x(i)= "set WinE_Construct = R1WinConstruction";
elseif x(i)== "44"
x(i)= "set WinE_Construct = R1WinConstruction";
elseif x(i)== "45"
x(i)= "set WinE_Construct = R1WinConstruction";
elseif x(i)== "46"
x(i)= "set WinE_Construct = R1WinConstruction";
elseif x(i)== "47"
x(i)= "set WinE_Construct = R1WinConstruction";
elseif x(i)== "48"
x(i)= "set WinE_Construct = R1WinConstruction";
end
end
for i = 49:72
if x(i) == "49"
x(i)= "set WinW_Construct = R1WinConstruction";
elseif x(i)== "50"
x(i)= "set WinW_Construct = R1WinConstruction";
elseif x(i)== "51"
x(i)= "set WinW_Construct = R1WinConstruction";
elseif x(i)== "52"
x(i)= "set WinW_Construct = R1WinConstruction";
elseif x(i)== "53"
x(i)= "set WinW_Construct = R1WinConstruction";
elseif x(i)== "54"
x(i)= "set WinW_Construct = R1WinConstruction";
elseif x(i)== "55"
x(i)= "set WinW_Construct = R1WinConstruction";
elseif x(i)== "56"
x(i)= "set WinW_Construct = R1WinConstruction";
elseif x(i)== "57"
x(i)= "set WinW_Construct = R1WinConstruction";
elseif x(i)== "58"
x(i)= "set WinW_Construct = R1WinConstruction";
elseif x(i)== "59"
x(i)= "set WinW_Construct = R1WinConstruction";
elseif x(i)== "60"
x(i)= "set WinW_Construct = R1WinConstruction";
elseif x(i)== "61"
x(i)= "set WinW_Construct = R1WinConstruction";
elseif x(i)== "62"
x(i)= "set WinW_Construct = R1WinConstruction";
elseif x(i)== "63"
x(i)= "set WinW_Construct = R1WinConstruction";
elseif x(i)== "64"
x(i)= "set WinW_Construct = R1WinConstruction";
elseif x(i)== "65"
x(i)= "set WinW_Construct = R1WinConstruction";
elseif x(i)== "66"
x(i)= "set WinW_Construct = R1WinConstruction";
elseif x(i)== "67"
x(i)= "set WinW_Construct = R1WinConstruction";
elseif x(i)== "68"
x(i)= "set WinW_Construct = R1WinConstruction";
elseif x(i)== "69"
x(i)= "set WinW_Construct = R1WinConstruction";
elseif x(i)== "70"
x(i)= "set WinW_Construct = R1WinConstruction";
elseif x(i)== "71"
x(i)= "set WinW_Construct = R1WinConstruction";
elseif x(i)== "72"
x(i)= "set WinW_Construct = R1WinConstruction";
end
end
for i = 73:96
if x(i) == "73"
x(i)= "set WinN_Construct = R1WinConstruction";
elseif x(i)== "74"
x(i)= "set WinN_Construct = R1WinConstruction";
elseif x(i)== "75"
x(i)= "set WinN_Construct = R1WinConstruction";
elseif x(i)== "76"
x(i)= "set WinN_Construct = R1WinConstruction";
elseif x(i)== "77"
x(i)= "set WinN_Construct = R1WinConstruction";
elseif x(i)== "78"
x(i)= "set WinN_Construct = R1WinConstruction";
elseif x(i)== "79"
x(i)= "set WinN_Construct = R1WinConstruction";
elseif x(i)== "80"
x(i)= "set WinN_Construct = R1WinConstruction";
elseif x(i)== "81"
x(i)= "set WinN_Construct = R1WinConstruction";
elseif x(i)== "82"
x(i)= "set WinN_Construct = R1WinConstruction";
elseif x(i)== "83"
x(i)= "set WinN_Construct = R1WinConstruction";
elseif x(i)== "84"
x(i)= "set WinN_Construct = R1WinConstruction";
elseif x(i)== "85"
x(i)= "set WinN_Construct = R1WinConstruction";
elseif x(i)== "86"
x(i)= "set WinN_Construct = R1WinConstruction";
elseif x(i)== "87"
x(i)= "set WinN_Construct = R1WinConstruction";
elseif x(i)== "88"
x(i)= "set WinN_Construct = R1WinConstruction";
elseif x(i)== "89"
x(i)= "set WinN_Construct = R1WinConstruction";
elseif x(i)== "90"
x(i)= "set WinN_Construct = R1WinConstruction";
elseif x(i)== "91"
x(i)= "set WinN_Construct = R1WinConstruction";
elseif x(i)== "92"
x(i)= "set WinN_Construct = R1WinConstruction";
elseif x(i)== "93"
x(i)= "set WinN_Construct = R1WinConstruction";
elseif x(i)== "94"
x(i)= "set WinN_Construct = R1WinConstruction";
elseif x(i)== "95"
x(i)= "set WinN_Construct = R1WinConstruction";
elseif x(i)== "96"
x(i)= "set WinN_Construct = R1WinConstruction";
end
end
Mohammad Dabbagh
Mohammad Dabbagh 2020년 10월 18일
편집: Mohammad Dabbagh 2020년 10월 18일
However, by taking your approach, I just receives 1,2,3, or 4 for that "newIDFFile". Thanks again for yoyr help :)
xs = strings(1,96);
xs(1:24) = "set WinS_Construct = R1WinConstruction";
xs(25:48) = "set WinE_Construct = R1WinConstruction";
xs(49:72) = "set WinW_Construct = R1WinConstruction";
xs(73:96) = "set WinN_Construct = R1WinConstruction";
newIDFFile = regexprep(readIDFFile, '@@P(\d+)@@', '${xs{str2double($1)}}')
This will not give back 1, 2, 3, or 4 for readIDFFile unless readIDFFile is already 1, 2, 3, or 4.
Here, readIDFFile is assumed to be a character vector or string object containing text that has @@P in places.
Your x is not the input: your readIDFFile is the input.
@Walter Roberson
Awesome! I truly appreciate all your continued help. Thank you so much!
Mohammad Dabbagh
Mohammad Dabbagh 2020년 10월 19일
편집: Mohammad Dabbagh 2020년 10월 19일
I meant variable R values. for instance, set WinS_Construct = R1WinConstruction, set WinS_Construct = R2WinConstruction, set WinS_Construct = R3WinConstruction, and set WinS_Construct = R4WinConstruction
As my x-values varries between 1 to 4
Here is the x.mat file
Thanks @Walter Roberson again!
I do not understand what you are asking. Your x.mat contains a newIDFFile variable that looks to have had the @@ properly replaced when I compare to readIDFFile. You do not have variables Obj1, Obj2 or similar in .mat and you do not have any R variable either. Your x values are not between 1 and 4, your x values are
>> x([1 48 72 end])
ans =
1×4 string array
Columns 1 through 3
"set WinS_Construct = R1WinConstruction" "set WinE_Construct = R1WinConstruction" "set WinW_Construct = R1WinConstruction"
Column 4
"set WinN_Construct = R1WinConstruction"
I do see that you have lb = ones(1,96) and ub = 4*ones(1,96), but what does that have to do with the price of bananas in Walla Walla, Washington?
It looks like you might be trying to work with EnergyPlus ? https://bigladdersoftware.com/epx/docs/8-3/auxiliary-programs/idfeditor.html
Mohammad Dabbagh
Mohammad Dabbagh 2020년 10월 19일
편집: Mohammad Dabbagh 2020년 10월 19일
oh, never mind.. Actually the problem is that my code is more complex and I just showed a portion of that to you. I figured it out BTW.
Thanks,

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Bruno Luong
Bruno Luong 2020년 10월 15일
편집: Bruno Luong 2020년 10월 15일
newIDFFile = readIDFFile;
for k=1:length(x)
newIDFFile = strrep(newIDFFile, sprintf('@@P%d@@',k), x(k));
end

댓글 수: 2

Awesome. Thanks :)
Hi again @Bruno Luong
Thank you so much again for your help. However, I'm not sure why my first 24 variables are not being replaced. Any idea? Thanks
P.S i also tried the following, but it didn't make any difference.
sprintf('@@P%u@@',k), x(k))

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by