0
votes

I plot something using as basis two matrices built with meshgrid.

[U,V] = meshgrid(Y,X);

Inside a function I build another pair of matrices

[A,B] = function(input)

and therefore I plot

plot((U((length(U)+1)/2,:)),A((length(U)+1)/2,:));
plot((V((length(U)+1)/2,:)),B((length(U)+1)/2,:));

If U and V are of this kind:

U= 1 2 3 4   V= 1 1 1 1
   1 2 3 4      2 2 2 2
   1 2 3 4      3 3 3 3
   ...          ...

I want to modify A in order to have the same plot but with U transposed meaning like this

U= 1 1 1 1   V= 1 2 3 4
   2 2 2 2      1 2 3 4
   3 3 3 3      1 2 3 4
   ...          ...

Means that now U has fixed values along the rows and changes along the columns, I want to have fixed values along the columns and change along the rows and the mathematical way to do it is to transpose U.

Is there another way to do it or how can I modify A to get the same plot? Of course transposing A doesn't work. A is a built like the sum of four input parameters (input of the function) A has let's say random values but the important thing is that the center row and column are approximately zero like this

A= -1.7 -1.6 ... 0 ... 1.6 1.7 
   -1.6 -1.5 ... 0 ... 1.5 1.6
   ...           0
     0    0      0      0    0
   ...
   1.6  1.5 ... 0 ... -1.5 -1.6
   1.7  1.6 ... 0 ... -1.6 -1.7

U and V are of this kind

To get the same plot after transposing U and V is this way,

U=U'; V=V'; 
plot((V((length(U)+1)/2,:)),A((length(U)+1)/2,:));
plot((U((length(U)+1)/2,:)),B((length(U)+1)/2,:));

but I cannot use it because afterwards I write the values of A in a file.

1
It's not clear what you want and why "transposing A doesn't work". Could you add a small example with numbers? - Sembei Norimaki
I added the examples of the three matrices. Doesn't work because I already tried transposing U, V, A and B. It does work but only if I replace U with V and the other way round inside the plot, keeping A and B still. But even if the plot becomes correct, I cannot use it because I write A and B in two files. I need to modify in some way A and B before write, keeping the convention plotting U wrt A and V wrt B - Shika93
What about plot((U(:,(length(U)+1)/2)),A((length(U)+1)/2,:)); ? - Adiel
Like thisplot((U((length(U)+1)/2,:)),A((length(U)+1)/2,:)); works but as already says I use the plot to see if the result is correct but I would like to maintain the original code and act only on U, V, A and B. I mean keep everything like it is right now and modify just these four matrices because otherwise I'm not sure that the results are correct or not. - Shika93
But you change your X-axis data (U). Why do you think that changing Y-axis data (A), in any case, should compensate the X-axis change...? That's two different independent things. - Adiel

1 Answers

0
votes

It is still unclear what you want.

Your matrices U and V are meshgrids.

U= 1 2 3 4   V= 1 1 1 1
   1 2 3 4      2 2 2 2
   1 2 3 4      3 3 3 3

And you have matrices A and B which have a correspondence to this matrices U and V.

Example:

A= -1.7 -1.6 -1.5 -1.4      B= -2.7 -2.6 -2.5 -2.4 
   -1.6 -1.5 -1.4 -1.3         -2.6 -2.5 -2.4 -2.3
   -1.5 -1.4 -1.3 -1.2         -2.5 -2.4 -2.3 -2.2

Now you want to transpose U and V:

U= 1 1 1 1   V= 1 2 3 4
   2 2 2 2      1 2 3 4
   3 3 3 3      1 2 3 4

So now if we pick one location in the matrix. eg (1, 3) that will have a U value associated (1) a V value (3), a A value (-1.5) and a B value (-2.5)

If you transpose U and V, the location (1,3) will have values U,V,A,B = (3, 1, -1.5, -2.5). As you can see, the values of A and B are mapped to different values of U and V (basically because you transposed U and V).

So transposing A and B you will have the correct mapping again.

EDIT:

You are basically plotting V in the Xaxis and A in the Yaxis. That basically means that each element of A is associated to an element of V to form a 2D coordinate.

If you now transpose V, the X elements will be arranged differently, so you have to rearrange the elements of A so the mapping stays the same.

That means that you need to do the same operation to both matrices to keep the mapping unchanged, since you are transposing V you also need to transpose A.

I asked for a numeric example, you the one provided is unclear. Provide an example of what you currently have (matrices + plot) and what you want to achieve (matrices and plot). Just do the example with a small 3x3 matrix and we will see what you want to do.