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.

[Solved] -- Geometry Creation using a LOOP

Please login with a confirmed email address before reporting spam

I am attempting to create a 2nd order Bezier curve using a Matlab script file. The number of points that I would like to process are extraordinary on the order of 500 - 1000; maybe even more. My data is set up in a text file that I can import into matlab using the load command. I have inserted what code I currently have below. When I run this in comsol it only outputs the last curve: named CO495. How can i get all the curves to be on the same plot? i.e. CO1 to CO495?

Thank you for your help!
Markthomas

%******************Start of M-file***********************
%Load Data
load 'Coord.txt'
x = Coord(:,1);
y = Coord(:,2);

%Initial Conditions
i = 1; j = 2; k = 3;

% Geometry objects
clear s

while k<=length(x)

% Geometry
carr=curve2([x(i), x(j), x(k)],[y(i),y(j),y(k)],[1,0.52,1]);
g4=geomcoerce('curve',carr);

s.objs={g4};
s.name={['CO' num2str(i)]};
s.tags={'g4'};

fem.draw=struct('s',s);
fem.sdim = {'x','y'};
fem.frame = {'ref'};
i = i+2; j = j+2; k = k+2;

end

6 Replies Last Post 2011年4月18日 GMT-4 09:42
Ivar KJELBERG COMSOL Multiphysics(r) fan, retired, former "Senior Expert" at CSEM SA (CH)

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 2010年6月5日 GMT-4 08:19
Hi

Ido not have comsol and matlab here from home, but shouldnt you index these too:

g4=geomcoerce('curve',carr);

s.objs={g4};
s.name={['CO' num2str(i)]};
s.tags={'g4'};


for me I read only 1 item, and if you go through all its only the "last one" remaining.

If you make a complex geoemtry with 2-3 or more items, COSMOL stores g1 g2 g3 g4 ... and the name list contains all names

check it out
Have fun Comsoling
Ivar
Hi Ido not have comsol and matlab here from home, but shouldnt you index these too: g4=geomcoerce('curve',carr); s.objs={g4}; s.name={['CO' num2str(i)]}; s.tags={'g4'}; for me I read only 1 item, and if you go through all its only the "last one" remaining. If you make a complex geoemtry with 2-3 or more items, COSMOL stores g1 g2 g3 g4 ... and the name list contains all names check it out Have fun Comsoling Ivar

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 2010年6月5日 GMT-4 12:48
I tried to index the following as:

g(i)=geomcoerce('curve',carr);

s.objs={g(i)};
s.name={['CO' num2str(i)]};
s.tags={'g(i)'};

but COMSOL doesn't like that... I am not sure of a way to index variable names i.e.

g1...g500

Do you know how to do this?
I tried to index the following as: g(i)=geomcoerce('curve',carr); s.objs={g(i)}; s.name={['CO' num2str(i)]}; s.tags={'g(i)'}; but COMSOL doesn't like that... I am not sure of a way to index variable names i.e. g1...g500 Do you know how to do this?

Ivar KJELBERG COMSOL Multiphysics(r) fan, retired, former "Senior Expert" at CSEM SA (CH)

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 2010年6月5日 GMT-4 12:59
Hi

not like that (I have no direct access to COMSOL from home), but really make a geometry from the GUI interface and save as a M file or just analyse your history.m file, and compare.
Then check that the naming is the same w.r.t. chr and ' '

Good luck
Ivar
Hi not like that (I have no direct access to COMSOL from home), but really make a geometry from the GUI interface and save as a M file or just analyse your history.m file, and compare. Then check that the naming is the same w.r.t. chr and ' ' Good luck Ivar

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 2010年6月7日 GMT-4 08:46
I figured out how to create a geometry using a loop (while loop or for loop) in COMSOL/MATLAB... It finally occurred to me what I had to do... I guess I am a little out of practice! Thank you for your help!

Markthomas
I figured out how to create a geometry using a loop (while loop or for loop) in COMSOL/MATLAB... It finally occurred to me what I had to do... I guess I am a little out of practice! Thank you for your help! Markthomas

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 2011年3月25日 GMT-4 11:29

I figured out how to create a geometry using a loop ...


So let us know, please!
[QUOTE] I figured out how to create a geometry using a loop ... [/QUOTE] So let us know, please!

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 2011年4月18日 GMT-4 09:42
Hi,

1) I have an arc that form my 2-D geometry. I also have an array of straight lines(y=constant) that cut my arc splitting into multiple arcs.
2) I need to move my multiple arcs to different positions.
3) So i select the arc to be moved.
4) Now I need to access the index of the array of straight line that is nearest to this arc.
5) So, I need to loop through the existing array and extract the y-coordinate of this straight line from the array.
6) Then retrieve the min y-position of the arc selected for moving.
7) Use if condition to check if y of line exceeds y of the appropriate arc.
8) Based on the above comparison, decide where to place my arc.
9) The displacement through which I take the arc will have the array index that is to be retrieved in 4.

I do not expect an exact solution to the problem but would be glad even if I can get hints on
a) how to access the index of an array of geometric object.
b) how to write if condition
c) how to write for loop

Note: I am flexible to choose between 3.5 and 4.1 or even integrating matlab with comsol if necessary though I have never tried it before.
Hi, 1) I have an arc that form my 2-D geometry. I also have an array of straight lines(y=constant) that cut my arc splitting into multiple arcs. 2) I need to move my multiple arcs to different positions. 3) So i select the arc to be moved. 4) Now I need to access the index of the array of straight line that is nearest to this arc. 5) So, I need to loop through the existing array and extract the y-coordinate of this straight line from the array. 6) Then retrieve the min y-position of the arc selected for moving. 7) Use if condition to check if y of line exceeds y of the appropriate arc. 8) Based on the above comparison, decide where to place my arc. 9) The displacement through which I take the arc will have the array index that is to be retrieved in 4. I do not expect an exact solution to the problem but would be glad even if I can get hints on a) how to access the index of an array of geometric object. b) how to write if condition c) how to write for loop Note: I am flexible to choose between 3.5 and 4.1 or even integrating matlab with comsol if necessary though I have never tried it before.

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.