## how to change axis of a matix?

### Asliddin Komilov (view profile)

on 13 Sep 2019
Latest activity Edited by Bruno Luong

on 15 Sep 2019

### Bruno Luong (view profile)

my matrix is M(x,y,z) where:
x=1:90
y=1:3:120
z=1:40
and
c=y./z
and I need to convert M into N(x,c).
Any ideas?

Rik

### Rik (view profile)

on 13 Sep 2019
consider a 2D example:
M=[1 2 3
4 5 6
7 8 9];
There are the same number of rows and columns ([1 2 3]). What would it mean if I reduce this to a single variable? Should M only keep 3 values? Should I have 9 options for the new parameter? These questions need to be answered for your situation as well.
Asliddin Komilov

### Asliddin Komilov (view profile)

on 14 Sep 2019
I also suspect that length(c)=y*z, still need to know how to do it.
Walter Roberson

### Walter Roberson (view profile)

on 14 Sep 2019
No, length of y and z are the same and y./z would have the same length.
Some of what you wrote does not seem to make sense until you start talking about grids of data, but then you have to ask about the sizes of the grids.

R2016a

### Bruno Luong (view profile)

on 15 Sep 2019
Edited by Bruno Luong

### Bruno Luong (view profile)

on 15 Sep 2019

Ufun = @(X,Y,Z) X;
Vfun = @(X,Y,Z) Y./(Z+200);
[X,Y,Z] = ndgrid(x,y,z);
U = Ufun(X,Y,Z);
V = Vfun(X,Y,Z);
U = U(:);
V = V(:);
[umin,umax] = bounds(U);
nu = 21;
u = linspace(umin,umax,nu);
[vmin,vmax] = bounds(V);
nv = 21;
v = linspace(vmin,vmax,nv);
[~,~,I] = histcounts(U,u);
[~,~,J] = histcounts(V,v);
N = accumarray([J I], M(:), [nu nv]-1, @mean, NaN);
midfun = @(x) 0.5*(x(1:end-1)+x(2:end));
u = midfun(u);
v = midfun(v);
surf(u,v,N);
xlabel('u (=x)');
ylabel('v (=y/(200+z)');  ### Walter Roberson (view profile)

on 14 Sep 2019

[X, Y, Z]=ndgrid(1:90,1:3:120,1:40);
C = round(ceil(Y./Z));
N = accumarray([X(:), C(:)], M(:), [], @mean, nan);
surf(N, 'edgecolor', 'none')
xlabel('x')
ylabel('c')
Or possibly N.' instead of N

Stephen Cobeldick

### Stephen Cobeldick (view profile)

on 15 Sep 2019
Please explain how you want to deal with the discontinuity in the middle of y./z:
>> plot(y./z) Asliddin Komilov

### Asliddin Komilov (view profile)

on 15 Sep 2019
I may use C=((y-z)./y); main thing is to obtain the value of M at x by some ratio of y and z, so I can make surface out of it.
Walter Roberson

### Walter Roberson (view profile)

on 15 Sep 2019
(y-z)/y is 1-z/y and since z and y both include 0, you still have nan and infinities.