1
votes

I have been trying to use the subplot function in Matlab, using the following code:

x = 0:10;
figure
subplot(2,2,1); plot(x,data_matrix(1,:))
subplot(2,2,2); plot(x,data_matrix(2,:))
subplot(2,2,3); plot(x,data_matrix(3,:))
subplot(2,2,4); plot(x,data_matrix(4,:))

However, when I run this simple code, the only thing that displays is a single figure with a plot of the last data vector, data_matrix(4,:). No errors show up. Rather, subplots are simply not being generated. Am I doing something incorrectly, or is there a potential error with my programming environment that's keeping me from displaying subplots?

1
clear everything, and comment out 'figure'. Does that help? - Flynn
No, I still get the same result. - Matthew Brown
Transpose matrices likes data_matrix(1,:).'. - OmG
I just tried that, and it also doesn't work. - Matthew Brown
Restart matlab? - Flynn

1 Answers

1
votes

Are you sure data_matrix(1,:) contains what you expect? You might want to check that out. Also, it'd great if you provided the minimal piece of code that reproduce your problem. Provided piece doesn't reproduce the problem because you don't provide access to data_matrix matrix which I suspect is causing the problem, because running this piece of code

x=0:10;
data_matrix=rand(4,11);

figure
subplot(2,2,1); plot(x,data_matrix(1,:))
subplot(2,2,2); plot(x,data_matrix(2,:))
subplot(2,2,3); plot(x,data_matrix(3,:))
subplot(2,2,4); plot(x,data_matrix(4,:))

works perfectly, as you can see below (I used a rand to recreate a well-formed data_matrix matrix)

output of piece of code