1

I have a matrix of, say:

size P = zeros(2,2,100);

Let's try to plot the first element of each of these matrices, like this:

plot(1:1:100, P(1,1,:))

This does not work. What is the proper way to do it?

2 Answers 2

5

Try plot(squeeze(P(1,1,:)).

The squeeze() function removes singleton dimensions (dimensions whose size are 1).

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

Comments

0

Solution: Create arrays manually. Not very elegant but works.

% tl = top left, br = bottom right, etc.
for i=1:1:100
    tlplot(i) = P(1, 1, i);
    trplot(i) = P(1, 2, i);
    blplot(i) = P(2, 1, i);
    brplot(i) = P(2, 2, i);
end

Then, for instance:

plot(1:1:100, tlplot)

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.