0

Consider the three-dimensional arrays

A = rand(3,4,5);
B = rand(3,4,5);

plot(A(:,1,1),B(:,1,1))
plot(A(1,:,1),B(1,:,1))

This all works fine, however

>> plot(A(1,1,:),B(1,1,:))
Error using plot
Data may not have more than 2 dimension

Is there a quick way around this a way around this other than using reshape()?

1 Answer 1

3

you should use squeeze to remove singleton dimensions:

plot(squeeze(A(1,1,:)),squeeze(B(1,1,:)))

another option is to shift matrix dimensions using shiftdim

plot(shiftdim(A(1,1,:),1),shiftdim(B(1,1,:),1),'o')
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks natan, I was unaware of squeeze().

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.