[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: searching for the elegant code (matrix indexing and more)
From: |
Markus Appel |
Subject: |
Re: searching for the elegant code (matrix indexing and more) |
Date: |
Thu, 23 Jan 2014 11:43:11 +0100 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.2.0 |
On 01/22/2014 09:49 PM, Andrei Bobrov wrote:
> [a,b,c,d,e] = ndgrid(1:2);
> sig1 = a.*b.^2 - c.*d.^3 +10*e;
>
I guess you could save some memory by using automatic broadcasting:
dim = 11;
a = (1:dim)(:);
sig = a .* shiftdim(a,-1).^2 - shiftdim(a,-2) .* shiftdim(a,-3).^3 +
10*shiftdim(a,-4);
For your mesh plots, are you sure that your example for A and D shouldn't be:
mesh(1:dim,1:dim,squeeze(sig(:,1,1,:,1)))
... ? Here is some idea for doing this automatically for all possible
combinations:
n = ndims(sig);
for i = 1:n
for j = (i+1):n
figure( (i-1)*n + j );
clf;
mesh( 1:dim , 1:dim , permute( sig,[i j (1:n)( (1:n)!=i & (1:n)!=j )]
)(:,:,1,1,1) );
xlabel('abcde'(i));
ylabel('abcde'(j));
endfor
endfor
Maybe there is some better way for the permute thing out there, possibly with
the subsref function.
HTH,
Markus