Jump to content
Science Forums

How would you code this?


Recommended Posts

Again in matlab but since it is about an algorithm the language isn't so important:

 

Consider the following code where the (...) denotes same for Y and Z:

SD.CompVol.XStep = 0.2;
(...)
SD.CompVol.X = [-4: SD.CompVol.XStep :4];
(...)
SD.CompVol.tX= length(SD.CompVol.X)
(...)

 

This is made in order to subdivide a given volume into subcells (called Voxels). Now imagine (which in the near future will be true) that is the volume of a part of the brain one wants to consider. Now imagine that on part of the surface of the above defined volume a sensor is put (size in X [-3.5,3.5] in Y [-1.5,1.5]). I need to define a matrix which is 1 in all the volume under the sensor and zero everywhere else.

 

My idea so far was to define Sd.Sensor.X and SD.Sensor.Y the same way as above and then make a few for loops with if statements, but I think this is not very efficient...

Link to comment
Share on other sites

Well, this is how it looks now, but there has to be an easier and more efficient way:

for i1=1:tX
           for j1=1:tY
             for k1=1:tZ
               if i1>SD.SrcPos(1,1) && i1<SD.SrcPos(size(SD.SrcPos,1),1)
                 if j1>SD.Det.Pos (2,2) && j1<SD.Det.Pos (1,2)
                   temp(i1,j1,k1)=1;
                 end
               end
             end
           end
         end

where

SD.SrcPos(1,1) =-3

SD.SrcPos(size(SD.SrcPos,1),1)=3

SD.Det.Pos (2,2)=-1.75 (wrong interval above)

SD.Det.Pos (1,2)=1.75

Link to comment
Share on other sites

With nx being tX it works the following way:

temp=zeros(nx,ny,nz);%qqqqqq change this for all choices of mu's
           
         for ix=1:nx
           for jy=1:ny
             for kz=1:nz
               if SD.CompVol.X(ix)>SD.SrcPos(1,1) && SD.CompVol.X(ix)<SD.SrcPos(size(SD.SrcPos,1),1)
                 if SD.CompVol.Y(jy)>SD.Det.Pos (2,2) && SD.CompVol.Y(jy)<SD.Det.Pos (1,2)
                   temp(ix,jy,kz)=1;
                 end
               end
             end
           end
         end

Link to comment
Share on other sites

some thoughts:

sanctus, trying to model a brain, but you are using a square coordinate system, would it not be easier to use hemispherical coordinates to better show position in a hemispherical object (well you would need 2 planes for 2 hemispheres of the brain). I mean its just something to consider.

 

I need to learn matlab, it seems to be the language of science, and science i like :rolleyes:

 

ok so you are iterating somethine based on multiple dimensions (ix jy kz), i dont quite think that there is a much more efficient way of doing that then iterating it across all 3 dimension with 3 nested loops, like you have.

Link to comment
Share on other sites

You don't really have to learn Matlab. I do not see it as the language of science, since it is too slow for real simulations...C++ is much better and if you really have to invert matrices or something like that you could call the Matlab routine from the C program...

Another reason why you don't have to learn Matlab is because it is like powerpoint the first time you use it you learn how to use it...

An example of how it is not hard to learn Matlab the SD above is a structure you define SD when you define its first field (nothing like struct {...}SD;) ; any added field can also be a structure hence if you want a structure Pets for example holding average values of heigth and weight of cats and dogs you just type

Pets.Cats.heigth=10;
Pets.Cats.weigth=7;
Pets.Dogs.heigth=20;
Pets.Dogs.weigth=15;

This all you need to do to declare and define a structure (of structures in this case).

 

 

As to your suggestion, I do not want to model the brain, I just want to get a spatial resolution of the region activate by some stimuli and there it is small enough to be modelled in a Cartesian way. It is all about implementing some image reconstruction techniques (like SIRT or even better Levelset).

 

Thanks for saying that it is the

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...