Path: news.mathworks.com!not-for-mail
From: "Tapos " <tapos1008@gmail.com>
Newsgroups: comp.soft-sys.matlab
Subject: inserting conditional data in a multidimensional matrix without using nested loop
Date: Thu, 9 Sep 2010 13:06:24 +0000 (UTC)
Organization: Univ of Glamorgan
Lines: 26
Message-ID: <i6am4g$7s7$1@fred.mathworks.com>
Reply-To: "Tapos " <tapos1008@gmail.com>
NNTP-Posting-Host: webapp-02-blr.mathworks.com
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1284037584 8071 172.30.248.37 (9 Sep 2010 13:06:24 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Thu, 9 Sep 2010 13:06:24 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 2488201
Xref: news.mathworks.com comp.soft-sys.matlab:668790

hi,
how can i extract and change data from a multi-dimensional matrix?
i can create a matrix containing all zeros or ones using v=ones(8,8,8); then i need to modify some of the elements using conditional statement depending upon the position of the elements.
can anybody help me?

here is the code for the matrix with for loop and conditions:

<pre lang="MATLAB">
for Z=1:8
    for Y=1:8
        for X=1:8
            if ((Z==1) | (Z==8))
                V(X,Y,Z)=0;  % top and bottom layers
            elseif (.1)^2 < ( ((X-4.5)*.01)^2 + ((Y-4.5)*.01)^2 )
                V(X,Y,Z)=0;  % outside the tank
            elseif ((.03)^2 < (((X-4.5)*.01+0)^2+((Y-4.5)*.01+0)^2)) | ((Z-.4.5)*.01 > .4) | ((Z-4.5)*.01 < -.4)
                V(X,Y,Z)=1;  % outside the sample
            else
                V(X,Y,Z)=2;  % inside the sample
            end
        end  % x loop
    end      % y loop
end          % z loop
</pre>

thanks