1
votes

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

2 Answers

5
votes

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

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

0
votes

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)