I'm trying to combine two surface plots in a single figure. The problem is that one of the two is plotted on the wrong axis. The reason is that:
surface1 = surf(x,y,z)
surface2 = surf(x,z,y)
This is due to the mathematical equations behind x,z and y. I can't change them, i.e. rearrange z in terms of y for surface2.
Is there a way to map the two to the correct axes?

2 Kommentare

KSSV
KSSV am 30 Jul. 2021
An example image will help to understand the problem.
turjdlawef
turjdlawef am 30 Jul. 2021
Bearbeitet: Walter Roberson am 30 Jul. 2021
Sure, here's a screenshot:
The green one is rotated wrongly; this is because the z variable is p in this case, whilst for the yellow it is a. When
i.e.
yellow = surf(x,p,a), green = surf(x,a,p)
It seems to me that I can't change the order in surf because that means rearranging the underlying equations, which I can't do in this case. When I combine the two in a single figure, a and p are inverted. It's difficult to see graphically but I'm sure that that's the problem ... just don't know how to fix it :( This instead is what the correct blue surface should be:

Melden Sie sich an, um zu kommentieren.

 Akzeptierte Antwort

Walter Roberson
Walter Roberson am 30 Jul. 2021

1 Stimme

You can
ax = gca;
yellow = surf(ax, x, p, a);
hold(ax, 'on')
M = [1 0 0 1; 0 0 1 0; 0 1 0 0; 0 0 0 0];
hg = hgtransform(ax, 'Matrix', M);
green = surf(hg, x, a, p);
hold(ax, 'off')
xlim(ax, 'auto'); ylim(ax, 'auto'); zlim(ax, 'auto');

5 Kommentare

I get the following error:
Error using hgtransform
Invalid value for Matrix property.
ax = gca;
yellow = surf(ax, x, p, a);
hold(ax, 'on')
M = [1 0 0 0; 0 0 1 0; 0 -1 0 0; 0 0 0 1];
hg = hgtransform(ax, 'Matrix', M);
green = surf(hg, x, a, p);
hold(ax, 'off')
xlim(ax, 'auto'); ylim(ax, 'auto'); zlim(ax, 'auto');
hgtransform is insisting that one of the axes be negative; I am not sure why that is.
M = [1 0 0 0; 0 0 -1 0; 0 1 0 0; 0 0 0 1];
is another matrix that is accepted.
It now tells me the following for the 2nd surf call (green)
Data dimensions must agree.
Is it because, after hg, I've recreated a?
a = meshgrid(linspace(0,1,10));
Walter Roberson
Walter Roberson am 30 Jul. 2021
In order for green = surf(hg, x, a, p); to work, then:
  • if x is a vector, then length(x) == size(p,2) -- columns not rows
  • if x is an array, then size(x) == size(p)
  • if a is a vector, then length(a) == size(p,1) -- rows not columns
  • if a is an array, then size(a) == size(p)
It is not an error to use an array for x by a vector for a, or a vector for x but an array for a, or a vector for both or an array for both -- but they have to match the appropriate dimension of p.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Produkte

Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by