1

I have such a code;

figure;
    for a = 1:length(weekM')
        tday_cell = day_cell(week_cell == weekM(a));
        for b = 1:length(days)
            subplot(length(weekM'), 7, b);
            if strcmp(first_entranceM{a, b}, '0') 
                plot(peaks);
                l = [l; 0];
            else
                tms_cell = ms_cell(week_cell == weekM(a));
                ttms_cell = tms_cell(strcmp(tday_cell,days{b}));
                l = [l; ttms_cell];
                plot(ttms_cell);
            end
        end
    end

I want to plot graphs with subplot function as subplot(3,7,[1:2:3...]). That is, I want to plot graph which has 3 lines, and 7 graphs on each line.

But in my case, it only shows the last line on the first line, and I can't see the remaining graphs.

I'm sure that the data to plot previous graphs are not being lost, but I don't understand why there are missing graphs.

Could you help me to fix this problem?

9
  • 1
    what exactly do you mean by the elipses in subplot(3,7,[1:2:3...])? Writing subplot(3,7,[1:2:3]) would the plot a single axis over the first, second and third grid location, which sounds contrary to what you desire. Also, when you say "lines" are you referring to line plots or rows of the grid formed by calling subplot? Commented Jun 25, 2015 at 15:30
  • 1
    length(weekM') = 3 presumably? What is the size and variable type of ttms_cell? Commented Jun 25, 2015 at 15:37
  • 1
    You lack a basic understanding of how subplot works. I've marked this post as duplicate to a post I wrote a while ago. Read that, and you can figure out why your code isn't working. Hint: It's the b term in your subplot call. Commented Jun 25, 2015 at 15:56
  • 1
    @rayryeng: I don't think it's a duplicate of the linked question. The OP has not only the wrong addressing but needs a solution for his problem because it's not only about changing b. Commented Jun 25, 2015 at 16:07
  • 1
    @Matt - That's right. The b term needs to be changed. I didn't say that the b needs to be adjusted... it does need to be completely changed :) I would personally just put a counter in at the beginning, and increment by 1 each time a plot is made... but your sub2ind stuff works too. I'm still gonna leave it as a duplicate because the code still lacks basic understanding on how subplot works. Commented Jun 25, 2015 at 16:10

1 Answer 1

1

Your line with the subplot-statement needs to be changed. The first argument is correct. The second argument represents the number of columns and needs to be set to 7 here, since you have 7 days. The last argument is the index of the addressed subplot and needs to be changed in every iteration.

This index can be generated using the sub2ind-function, which calculates the index from the subscripts. The following line can be used instead of yours:

subplot(length(weekM'),7,sub2ind([7,length(weekM')],b,a));
Sign up to request clarification or add additional context in comments.

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.