6 views (last 30 days)

Show older comments

Dear all, I have a set of experimental conditions obtained by sweeping 3 parameters A, B, C. For each condition, I have 1 experimental data. The experimental conditions are listed in an order associated with the cartesian product of list of 3 parameters A, B and C, said vector A(1..n), B(1..m), C(1..p). Threfore for any [A(i) B(j) C(k)], I have 1 experimental data located at the index ind=f(i,j,k) in the matrix of cartesian product of list of A,B and C.

With this index, I can get the experimental value M(index,1) for column 1 of my data, for example.

A = [1 2 3]; B = [10 20 30]; C=[100 200 300] ; R is the cartesian product of list of parameters A,B,C and has a length of mxnxp=27 (in this example). It must give this order of row lines of R as : 1 10 100 ; 1 10 200 ; 1 10 300 ; 1 20 100 ; etc... It is worth to notice that meshgrid(A,B,C) does not give row lines listed above but 1 10 100 ; 1 20 100 ; 1 30 100 ; 2 10 100 ; 2 20 100 ; 2 30 100 ; 3 10 100 ; ... this is not what I want.

The ascending index value of R should corresponds to the correct combination of parameters used in the order A then B then C. Therefore the corresponding 'index' of vector M(index,1) corresponds to the row line of R.

Here comes my hurdle for several weeks: I want to display data on 3D graph (using scatter3, plot3, or surf3). I need to define (X,Y,Z,Color).

X can be either A, B or C. Y can be either A, B, or C. Legend Color can be either A, B, or C. Z is the corresponding data located at the index of R. But I need to build up a 2D or 3D vector for Z.

Indeed plot3(A,B,Z,C) is the same than plot3(B,A,Z,C). In case of 3 parameters (A,B,C), the 3D graphs should be displayed as : plot3(A,B,Z,C) , plot3(A,C,Z,B), plot3(B,C,Z,A).

How to build up the matrix Z by picking up the correct index of R in order to display each 3D graphs?

(I am sorry, I spent a long time to synthetise my question, but it helped me to better define my problem. Still, I feel that for readers, it could be not enough clear. I am so sorry for that).

My final goal is to be able to solve this problem for N parameters (N=1 to 5). The data are recorded in a fixed order (A,B,C,...).

I will be more than happy to get any answer, at least before my head will explose ! Sincrely yours Laurent

Bob Thompson
on 27 Jul 2018

I could be totally wrong, but I think it's pretty simple. Just need a loop for your color parameter. Suppose we build plot3(A,B,Z,C).

hold on

for c = 1:size(data,3) % Loop through C elements

z = data(:,:,c);

plot3(A,B,z,C);

... % Add other plot things here.

end

Looping through one of the other parameters would be very similar.

for b = 1:size(data,2);

z = data(:,b,:);

...

end

Bob Thompson
on 31 Jul 2018

Hey, if it works, it works. Understanding is good though.

I used [Y, X] instead of [X, Y] because that is how it is defined by the function, not my personal preference. The same applies for the dimensions of Z used in surf.

surf(Z) plots Z in a 3D surface with X and Y values set as integers for each row and column of Z. surf(X,Y,Z) plots Z in a 3D surface with X and Y values set as corresponding rows and columns of Z. I.e. if X = [1 2 3] and Y = [10 20 30] and you use surf(Z) then Z(1,1) will be plotted at the (x, y) coordinate of (1,1) because no X and Y were specified in surf. But if you use surf(X, Y, Z) then Z(1,1) will be plotted at (1, 10), to properly correspond to the X and Y arrays specified.

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

Start Hunting!