MATLAB Answers

X must have length equal to the number of rows in Y, but I'm pretty sure they're the same size

조회 수: 19(최근 30일)
Eric Simpson
Eric Simpson 8 Apr 2021 14:52
답변: dpb 8 Apr 2021 15:12
Hey all,
I'm trying to plot something, but I'm getting the error mentioned in the title even though I think everything I'm tying to plot is the same size 1x12).
My code is below; I'm trying to put distance on the X axis and plot the other 3 variables on the Y axis.
Edit: I've also tried it within the (1:12) callouts on the first two variables, same error
salinity = [31 31 33 26 25 22 22 22 22 22 20 21];
distance = [0 206.4 367.2 486.9 616.3 743.3 1141.8 1145.1 1225.3 1232 1232 1232];
nutrients14 = readtable('C:\Users\ejs7c\OneDrive\Desktop\transect14data.xlsx');
nutrients181 = readtable('C:\Users\ejs7c\OneDrive\Desktop\transect181data.xlsx');
nutrients182 = readtable('C:\Users\ejs7c\OneDrive\Desktop\transect182data.xlsx');
nutrients19 = readtable('C:\Users\ejs7c\OneDrive\Desktop\transect19data.xlsx');
pwnutr = readtable('C:\Users\ejs7c\OneDrive\Desktop\pwdata.xlsx');
stackedplot(distance(1:12), salinity(1:12), nutrients14.Var12(101:112), nutrients14.Var12(114:125));

채택된 답변

dpb 8 Apr 2021 15:12
nutrients14 is a table in which case those will be column vectors instead of row vectors and stackedplot needs one X and an array of Y. It puts each column in Y in the plot by sequence.
NB: You don't need subscript expressions for distance, salinity, but you need to group the Y variables into one array --
stackedplot(distance, [salinity.', nutrients14.Var12(101:112), nutrients14.Var12(114:125)]);

추가 답변(0개)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by