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

10 vues (au cours des 30 derniers jours)
Mohammad Dabbagh
Mohammad Dabbagh le 15 Oct 2020
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 commentaire
Mohammad Dabbagh
Mohammad Dabbagh le 15 Oct 2020
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.

Connectez-vous pour commenter.

Réponse acceptée

Walter Roberson
Walter Roberson le 17 Oct 2020
Modifié(e) : Walter Roberson le 18 Oct 2020
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 commentaires
Walter Roberson
Walter Roberson le 19 Oct 2020
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 le 19 Oct 2020
Modifié(e) : Mohammad Dabbagh le 19 Oct 2020
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,

Connectez-vous pour commenter.

Plus de réponses (1)

Bruno Luong
Bruno Luong le 15 Oct 2020
Modifié(e) : Bruno Luong le 15 Oct 2020
newIDFFile = readIDFFile;
for k=1:length(x)
newIDFFile = strrep(newIDFFile, sprintf('@@P%d@@',k), x(k));
end
  2 commentaires
Mohammad Dabbagh
Mohammad Dabbagh le 15 Oct 2020
Awesome. Thanks :)
Mohammad Dabbagh
Mohammad Dabbagh le 17 Oct 2020
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))

Connectez-vous pour commenter.

Community Treasure Hunt

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

Start Hunting!

Translated by