フィルターのクリア

permute matrix dimensions: getting trickier ...

2 ビュー (過去 30 日間)
oxy
oxy 2014 年 3 月 19 日
編集済み: oxy 2014 年 3 月 19 日
Hi gurus,
i have a multidimensional matrix (M) and want to plot every combination of two of its dimensions in a mesh. Here is the solution we came up with for octave toguether with its community:
% generate matrix M
size=11;
for A=(1:size)
for B=(1:size)
for C=(1:size)
for D=(1:size)
for E=(1:size)
M(A, B, C, D, E) = A*B^2 - C*D^3 +10*E;
end
end
end
end
end
% plot all pair combinations of M dimensions
n = ndims(M);
for i = 1:n
for j = (i+1):n
figure( (i-1)*n + j );
clf;
mesh( 1:size , 1:size ,...
permute( M,[i j (1:n)( (1:n)!=i & (1:n)!=j )] )(:,:,1,1,1) );
xlabel('abcde'(i));
ylabel('abcde'(j));
end
end
The command permute does not work in this form on matlab. I could'nt find a way out. Could u help me?
thx...

回答 (2 件)

David Sanchez
David Sanchez 2014 年 3 月 19 日
I am a bit confused by the explanation of what you want. Is it something like this?
% plot all pair combinations of M dimensions
n = ndims(M);
for i = 1:size
for j =1:size
for k=1:size
figure();
clf;
[X,Y] = meshgrid(1:size);
mesh(X, Y ,M(:,:,i,j,k));
end
end
end

oxy
oxy 2014 年 3 月 19 日
編集済み: oxy 2014 年 3 月 19 日
hi david, that s not exactly what i want.
To make it clear, if my matrix M has 3 dimensions, each having size = 'size', then i need
for k=1:size, mesh(1:size, 1:size, M(:, :, k)), end
for k=1:size, mesh(1:size, 1:size, M(:, k, :)), end
for k=1:size, mesh(1:size, 1:size, M(k, :, :)), end
In fact i have more dimensions. Thus i want to make this looping over the dimensions automatic.
If you try the code below in octave u will see that it selects the dimensions 'a' and 'b' and properly sort all other dimensions after that. In this example i have n=6 dimensions
a=2; b=4 % this means i wanna mesh-plot dimensions 2 and 4 of M
n=6 % my matrix M has 6 dimensions in total
[a b (1:n)( (1:n)!=a & (1:n)!=b )] % this is how we sort the matrix M
% and this is how the permute cmd would look like.
% we just did not create the matrix M on this post, but the cmd works
permute(M,[a b (1:n)((1:n)!=a & (1:n)!=b )])(:,:,1,1,1) )
Thus i only need to for-loop over 'a' and 'b' with the permute command and i get all possible combinations between the dimenaions of M. See the way i did it in the first post.
I hope i made my aim clear now (°~°)

カテゴリ

Help Center および File ExchangeLine Plots についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by