MATLAB Answers

Scatter Plot: X and Y must be vectors of the same length

30 views (last 30 days)
Gabriela Acosta
Gabriela Acosta on 17 May 2021 at 0:00
Edited: Gabriela Acosta on 17 May 2021 at 0:17
SDT=[8702.28,7733.86,9790.18,5877.4,6690.84,6281.96,7846.98,5875.71,8098.65,6026.58,5885.59,4080.97,4940.49,4204.46,4451.12,5826,7848.93,5864.18,8618.89,7347.1,6591.14,10587.21,4378.77,9338.27,8005.15,7870.55,6886.67,7572.70,5493.41,9011.60,5239.10,7856.72,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,;5006.95,6865.74,7762.67,4773.47,3671.71,4199,8082.12,4572.81,10077.5,4594.14,6728.5,4954.73,4050.92,3381.5,6847.28,4714.70,5137.72,3128.31,6771.97,6570.7,5698.65,9422.3,3407.47,7059.24,7013.99,8845.63,4921.34,4584.04,3339.14,9423.47,5318.16,5403.89,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2];
scatter(SDT(1,33:48),SDT(1,1:8),'r.','jitter','on','jitterAmount',0.15);
hold on
scatter(SDT(1,33:48),SDT(1,9:16),'k.','jitter','on','jitterAmount',0.15);
scatter(SDT(1,33:48),SDT(1,17:24),'yo','jitter','on','jitterAmount',0.15);
scatter(SDT(1,33:48),SDT(1,25:32),'og','jitter','on','jitterAmount',0.15);
scatter(SDT(2,33:48),SDT(2,1:8),'r.','jitter','on','jitterAmount',0.15);
scatter(SDT(2,33:48),SDT(2,9:16),'k.','jitter','on','jitterAmount',0.15);
scatter(SDT(2,33:48),SDT(2,17:24),'yo','jitter','on','jitterAmount',0.15);
scatter(SDT(2,33:48),SDT(2,25:32),'og','jitter','on','jitterAmount',0.15);
I am having trouble understanding the error "X and Y must be vectors of the same length". I am in process of making a scatter plot of 2x48. I have made this same type of scattered plot 2x24 and it turned out ok, but for some reason I am having issues with the larger one. Here is what my script/code looks lke. Thank you for the help!

Accepted Answer

the cyclist
the cyclist on 17 May 2021 at 0:07
Edited: the cyclist on 17 May 2021 at 0:08
SDT=[8702.28,7733.86,9790.18,5877.4,6690.84,6281.96,7846.98,5875.71,8098.65,6026.58,5885.59,4080.97,4940.49,4204.46,4451.12,5826,7848.93,5864.18,8618.89,7347.1,6591.14,10587.21,4378.77,9338.27,8005.15,7870.55,6886.67,7572.70,5493.41,9011.60,5239.10,7856.72,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,;5006.95,6865.74,7762.67,4773.47,3671.71,4199,8082.12,4572.81,10077.5,4594.14,6728.5,4954.73,4050.92,3381.5,6847.28,4714.70,5137.72,3128.31,6771.97,6570.7,5698.65,9422.3,3407.47,7059.24,7013.99,8845.63,4921.34,4584.04,3339.14,9423.47,5318.16,5403.89,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2];
length(SDT(1,33:48))
ans = 16
length(SDT(1,1:8))
ans = 8
You are trying to plot points where you have defined the x-axis positions with a length-16 vector, and the y-axis positions with a length-8 vector. The error seems quite clear to me. What were you expecting/hoping would happen?
  1 Comment
Gabriela Acosta
Gabriela Acosta on 17 May 2021 at 0:15
Thank you very much for pointing that out, I definitely missed that. I am fairly new to MatLab, I am still trying to understand how things work. Thanks..

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!