r/matlab • • Sep 07 '22

Error using plot vectors must be same length

Post image
1 Upvotes

12 comments sorted by

1

u/Drezkul Sep 07 '22

What am I missing? Do I need to change .1000? I am trying to make a side by side graph.

9

u/tstiger Sep 07 '22

The variable years has 41 elements but the variable measles1931 only has 12 elements.

-3

u/Drezkul Sep 07 '22

How could I fix it? Would I have to create a new code like Measles1931 = measles(11, :);

2

u/tstiger Sep 07 '22

What are you trying to plot? The variable years presumably is just a list of the years between 1931 and 1971. You have a variable measles with is a matrix of dimension 41 x 12. The number of rows, I would think, corresponds to each year, but what are the 12 columns? And what is the relationship between measles1931 and measles?

ETA: My guess is that the columns correspond to months. Okay, do you want to plot the data for a given month (say, September) vs year or a yearly average vs year? Or something else?

-1

u/Drezkul Sep 07 '22

I am plotting a side by side graph of measles 1931 and measles 1941.

1

u/tstiger Sep 07 '22

What are measles1931 and measles1941?

1

u/Drezkul Sep 07 '22

They documented the number of cases of measles in New York city in 1931-1972. I am making side by side graphs for those two years.

6

u/tstiger Sep 07 '22

So, is measles1931 the number of cases for each month of 1931? If so, then you want to plot measles1931 versus month -- i.e., plot(1:12, measles1931), where the x axis would be the number of the month and the y axis would the number of cases in that month. You don't want to include the variable years, as you did in your example.

1

u/Drezkul Sep 07 '22

Thanks. I changed it and it has a graph side by side but it is says warning: ignoring legend entries. On the graph January is only coming up. How can I fix it?

2

u/wokka7 Sep 07 '22

Look at the legend entry in the mathworks documentation here

→ More replies (0)

2

u/[deleted] Sep 08 '22

My brother in christ windows key + shift + s let's you take screenshots.