Note: This discussion is about an older version of the COMSOL Multiphysics® software. The information provided may be out of date.

Discussion Closed This discussion was created more than 6 months ago and has been closed. To start a new discussion with a link back to this one, click here.

Increment of Variable/Argument name used in Function

Please login with a confirmed email address before reporting spam

Hi,

I'm trying to increment variable name in a command:

___________________
ie: model.geom('geom1').feature.create('b1', 'BezierPolygon');

Here I'll like to increment 'b1' each time loop is passing over this command (considering the command into a if loop per example)
____________________


Usually, I use evalc to increment matrix name in Matlab:
____________________
for i=1:10
evalc(['b' num2str(i) '=zeros(N,N)'])
end
____________________

Here it doesn't work, since Matlat interpret this as an undefined variable (since I do not assign anything to the variable)



I'm sur it is not complicated !

Any help would be appreciated.

3 Replies Last Post Apr 28, 2011, 8:48 p.m. EDT

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago Apr 28, 2011, 2:08 p.m. EDT
Also tried genvarname:

________________________
for i=1:12
v = genvarname(['b', num2str(i)]);
model.geom('geom1').feature('wp1').geom.feature.create('v', 'BezierPolygon');
end

_______________________


Doesn't work because it see only letter v
Also tried genvarname: ________________________ for i=1:12 v = genvarname(['b', num2str(i)]); model.geom('geom1').feature('wp1').geom.feature.create('v', 'BezierPolygon'); end _______________________ Doesn't work because it see only letter v

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago Apr 28, 2011, 3:07 p.m. EDT
Neither sprintf

model.geom('geom1').feature('wp1').geom.feature.create(sprintf('b%d',i), 'BezierPolygon');
Neither sprintf model.geom('geom1').feature('wp1').geom.feature.create(sprintf('b%d',i), 'BezierPolygon');

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago Apr 28, 2011, 8:48 p.m. EDT
Solved: here is how to proceed


if i=1:10
model.geom('geom1').feature('wp1').geom.feature.create(['b',num2str(i)], 'BezierPolygon');
end


Solved: here is how to proceed if i=1:10 model.geom('geom1').feature('wp1').geom.feature.create(['b',num2str(i)], 'BezierPolygon'); end

Note that while COMSOL employees may participate in the discussion forum, COMSOL® software users who are on-subscription should submit their questions via the Support Center for a more comprehensive response from the Technical Support team.