From: Volkan on 1 Jul 2010 21:17 Hi, I am trying to avoid for loops but I couldn't find an easy solution for the problem below: p1hf = [1,2;3,4]; nb = 2; % It might go up to 100 or so need a smarter solution p2hf = zeros(nb, nb, nb, nb); for a=1:nb for b=1:nb for c=1:nb for d=1:nb p2hf(a,b,c,d) = 2*p1hf(a,b)*p1hf(c,d) - p1hf(a,c)*p1hf(b,d); end end end end p2hf is 4-D. Is there an easy way to avoid these loops? Your help will be greatly appreciated.
From: Roger Stafford on 2 Jul 2010 00:19 "Volkan " <volkaned(a)hotmail.com> wrote in message <i0jemg$hka$1(a)fred.mathworks.com>... > Hi, > > I am trying to avoid for loops but I couldn't find an easy solution for the problem below: > > p1hf = [1,2;3,4]; > nb = 2; % It might go up to 100 or so need a smarter solution > p2hf = zeros(nb, nb, nb, nb); > for a=1:nb > for b=1:nb > for c=1:nb > for d=1:nb > p2hf(a,b,c,d) = 2*p1hf(a,b)*p1hf(c,d) - p1hf(a,c)*p1hf(b,d); > end > end > end > end > > p2hf is 4-D. Is there an easy way to avoid these loops? > > Your help will be greatly appreciated. - - - - - - - - - I think this does the same thing, but I'm not sure any time is saved. p2hf = reshape(reshape(p1hf,[],1)*reshape(p1hf,1,[]),nb,nb,nb,nb); p2hf = 2*p2hf-permute(p2hf,[1,3,2,4]); Roger Stafford
From: Zeeshan on 2 Jul 2010 00:58 Hi Roger I want to plot a 2D mesh of spherical pore bodies connected with throats. The 2D mesh could be a diamond lattice. The spherical pore bodies is of volume ((4 π/3 )r3 ) = l3 and the throat bodies are cylindrical which are of length l and have randomly chosen cross sectional area between 0 and l2. Also the volume of both pore and throat could be adjusted as desired. Can you help me in this ?
From: Walter Roberson on 2 Jul 2010 01:21 "Zeeshan " <zeeextra(a)yahoo.com> wrote in message <i0jrkt$44o$1(a)fred.mathworks.com>... > Hi Roger > > I want to plot a 2D mesh of spherical pore bodies connected with throats. Please do not add unrelated questions to an existing thread.
From: Roger Stafford on 2 Jul 2010 01:31
"Zeeshan " <zeeextra(a)yahoo.com> wrote in message <i0jrkt$44o$1(a)fred.mathworks.com>... > Hi Roger > > I want to plot a 2D mesh of spherical pore bodies connected with throats. The 2D mesh could be a diamond lattice. The spherical pore bodies is of volume ((4 π/3 )r3 ) = l3 and the throat bodies are cylindrical which are of length l and have randomly chosen cross sectional area between 0 and l2. Also the volume of both pore and throat could be adjusted as desired. > > Can you help me in this ? - - - - - - - - - - That is not ethical, Zeeshan. You have tacked your own question onto another person's entirely different thread. That is not the way to get questions answered. Also you have entered exactly the same question with precisely the same wording (except for the "Hi Roger") in at least four other threads today and yesterday. This is definitely not the way to cause other people to be willing to help you. Duplicate threads are very much frowned upon in this newsgroup. I certainly don't intend to help you. Roger Stafford |