Plotting groups of different size separately, also error message: Vectors must be the same length

1 vue (au cours des 30 derniers jours)
Hello!
I tried plotting some data and got the 'Error using plot. Vectors must be the same length.' error message.
I am trying to plot two sets of data:
G: 0.66, 0.05, 0.51, 0.4
B: 0.15, 0.03, 0.10, 0.62, 0.002, 0.10, 0.07, 0.2
using the following line of code: plot([1 2],[G; B], 'MarkerSize',15)
I know the error message is because the two groups are of different sizes, but is there a way to tell matlab that they are not paired, I just want them separate, but I want them plotted in that format?
Thanks!
Vyte

Réponse acceptée

Image Analyst
Image Analyst le 8 Sep 2022
You have 2 values for x (1 and 2) but you have 4 values in the G vector and 8 values in the B vector. Please give a complete list of all (x,y) coordinates that you'd like to plot.
G = [0.66, 0.05, 0.51, 0.4] % A 1 by 4 row vector.
G = 1×4
0.6600 0.0500 0.5100 0.4000
B = [0.15, 0.03, 0.10, 0.62, 0.002, 0.10, 0.07, 0.2] % A 1 by 8 row vector.
B = 1×8
0.1500 0.0300 0.1000 0.6200 0.0020 0.1000 0.0700 0.2000
y = [G; B] % Concatenate B below G vertically. (Won't work because # columns is different in the two row vectors).
Error using vertcat
Dimensions of arrays being concatenated are not consistent.
plot([1 2],[G; B], 'MarkerSize',15)
  9 commentaires
Image Analyst
Image Analyst le 9 Sep 2022
For every y value you must have an x value so the ones just makes sure of that. It creates a vector of all 1's since all of the G's are to be plotted with the same x value, not different ones. Same for B -- I made it 2 so it's apart from the G dots.
Vyte Jan
Vyte Jan le 9 Sep 2022
Makes sense! Thank you for your help and the explanation :)

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Scatter Plots dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by