Asked by Asliddin Komilov
on 13 Sep 2019

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?

Answer by Bruno Luong
on 15 Sep 2019

Edited by Bruno Luong
on 15 Sep 2019

Accepted Answer

load('testdata.mat');

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)');

Sign in to comment.

Answer by Walter Roberson
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
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
on 15 Sep 2019

Walter Roberson
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.

Sign in to comment.

Opportunities for recent engineering grads.

Apply Today
## 6 Comments

## KALYAN ACHARJYA (view profile)

## Direct link to this comment

https://se.mathworks.com/matlabcentral/answers/480253-how-to-change-axis-of-a-matix#comment_745538

## Rik (view profile)

## Direct link to this comment

https://se.mathworks.com/matlabcentral/answers/480253-how-to-change-axis-of-a-matix#comment_745539

## Asliddin Komilov (view profile)

## Direct link to this comment

https://se.mathworks.com/matlabcentral/answers/480253-how-to-change-axis-of-a-matix#comment_745614

## Rik (view profile)

## Direct link to this comment

https://se.mathworks.com/matlabcentral/answers/480253-how-to-change-axis-of-a-matix#comment_745683

## Asliddin Komilov (view profile)

## Direct link to this comment

https://se.mathworks.com/matlabcentral/answers/480253-how-to-change-axis-of-a-matix#comment_745851

## Walter Roberson (view profile)

## Direct link to this comment

https://se.mathworks.com/matlabcentral/answers/480253-how-to-change-axis-of-a-matix#comment_745855

Sign in to comment.