How to make random voids with for loop?
Mostrar comentarios más antiguos
Hi eveyone, I have a question regarding MATLAB and COMSOL. I have a membrane in COMSOL and I wanna add voids in the MATLAB code which is linked to COMSOL. The following code gives me random locatoin as 0 and 1, which, 1 means the location of a void.
x = linspace(-2,2,10) ; y = linspace(-2,5,10) ; [X,Y] = meshgrid(x,y) ; c = randi([0 1], size(Y))==1 P = [X(c) Y(c)] figure plot(X(c),Y(c), '.r') hold on plot(X(~c), Y(~c), '.b') hold off axis('padded') legend('1','0', 'Location','best')
I need a code that can give me the number of 1's (the number of voids in the membrane) and their locations.
Then, I know how write the code for one, two voids and so on in MATLAB linked to COMSOL. However, adding them by hands is very time consuming. The code is as follows:
model.component('comp1').geom('geom1').feature('wp1').geom.create('e1', 'Ellipse'); model.component('comp1').geom('geom1').feature('wp1').geom.feature('e1').set('semiaxes', {'R/10' 'R/15'}); model.component('comp1').geom('geom1').feature('wp1').geom.feature('e1').set('pos', {'0' '0'}); model.component('comp1').geom('geom1').feature('wp1').geom.create('e2', 'Ellipse'); model.component('comp1').geom('geom1').feature('wp1').geom.feature('e2').set('semiaxes', {'R/15' 'R/15'}); model.component('comp1').geom('geom1').feature('wp1').geom.feature('e2').set('pos', {'1.5e-4' '0'}); model.component('comp1').geom('geom1').feature('wp1').geom.create('dif1', 'Difference'); model.component('comp1').geom('geom1').feature('wp1').geom.feature('dif1').selection('input').set({'r1'}); model.component('comp1').geom('geom1').feature('wp1').geom.feature('dif1').selection('input2').set({'e1' 'e2'}); model.component('comp1').geom('geom1').run('wp1'); model.component('comp1').geom('geom1').run('fin');
In this code 'comp1' , 'geom1', 'wp1', 'dif1', selection('input') and selection('input2') aren't going to change. In a nutshel, How can I write a code which can generate a new membrane with random voids? More details: For instance if I have 10 voids, then I have e1 to e10 and for each one I should add their location in .set('pos', {'0' '0'}). Also I should add e1 to e 10 in selection('input2').set({'e1' 'e2'}).
Thank you all in advance.
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Code Performance en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
