0

I am trying to plot a figure using three matrices but somehow I couldn't understand. I have three matrices and an array. Suppose,

A =

     1     2     3

     4     5     4

     7     8     9

B =

     2     3    13

     5    11    10

     9     7     6


C =

     1     2     3
     2     3    13
     5    11    10 

and an array

Y= [0.001 0.0002 0.0004]. 

Now I want to plot it in such a way that array values should be on y axis while against 0.001, 0.002 and 0.0004 the matrices value should be arranged. for examples, the y=0.001, A(1,1)=1, y=0.0002, B(1,1)=2 y=0.0004, C(1,1)=1 for a single line.

and similarly process goes for A(i,j),B(i,j) and c(i,j) points using loop to plot all lines on a single figure.

Thanks

5
  • 1
    Your question is very confusing. Can you try to rephrase it, please? Commented Feb 20, 2017 at 13:57
  • @AnderBiguri I have three matrices and an array as shown above. Now I want to plot it in a way that these three values of an array (0.001, 0.0002, 0.0004) should be on the y-axis and on the x-axis, first value of matrix A should be plotted against 0.001 value of array and first value of matrix B should be plotted against second value of array which is 0.0002 and similarly for third value. Commented Feb 20, 2017 at 14:13
  • I don't understand. What does i,j stand for? axes x,y? Do you want to plot all values of A against 0.001, all values of B against 0.0002 and all values of C in 0.0004? And then connect all (i,j) pairs? Commented Feb 20, 2017 at 23:10
  • @ana, yes. Do you know how to do it? Commented Feb 21, 2017 at 0:42
  • I think @Florian's answer is just that Commented Feb 21, 2017 at 0:50

2 Answers 2

1

So, the first plot is plot([1,2,1],Y), the next one is plot([2,3,2],Y) and so on?

If so, you could do it like that

X = cat(3,cat(3,A,B),C);
X = reshape(permute(X,[3,1,2]),3,9);
plot(X,Y,'--x');

which gives a plot like this:

Resulting plot

Is this what you were looking for? If not, I didn't understand your question well and I'd like to ask you to rephrase it.

Sign up to request clarification or add additional context in comments.

Comments

0

You can create a 3D array (tensor) and access it in a loop.

T(:,:,1) = A;
T(:,:,2) = B;
T(:,:,3) = C;

figure;
for idi = 1:size(A,1)
    for idj = 1:size(A,2)
        plot(squeeze(T(idi,idj,:)).',Y); hold on;
    end
end

Accessing the third dimension is not fastest operation (as they are not store sequential in memory) and if the matrices are larger you might consider reshape.

I did not understand you wanted the vector Y to be on the x-axis or y-axis (and neither of those plots make sense to me) but I am sure you can modify the code from here for your needs.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.