I am getting error "The length of X must match the number of rows of Y."

7 vues (au cours des 30 derniers jours)
kalyani ohri
kalyani ohri le 21 Fév 2016
Commenté : kalyani ohri le 26 Fév 2016
RGB =imread('image.jpg');
hsv= rgb2hsv(RGB);
imshow(hsv);
r1=0.1;
r2=0.85;
i= 0:20:240;
s= 0.0:0.2:1.0;
wgray = 1 - bsxfun(@power, s(:), (r1*(255./(i(:).')).^r2) );
P = gradient(wgray,0.2);
Q= gradient(wgray,0.4);
R= gradient(wgray,0.6);
S= gradient(wgray,0.8);
T= gradient(wgray,1.0);
bar(i,P,);
please kindly help .

Réponse acceptée

Geoff Hayes
Geoff Hayes le 21 Fév 2016
kaylani - at which line are you observing this error? Note that when I run your code, the only problem I observe is with
bar(i,P,);
and the error is
Unbalanced or unexpected parenthesis or bracket.
Once I correct this (remove the final comma), then I see how it is this same line, invoking bar, that generates your error message.
Error using bar (line 58)
The length of X must match the number of rows of Y.
This is because your 'x' input, i (which should be renamed to avoid using MATLAB's representation for an imaginary number), is a 1x13 array whereas your 'y' input, P, is a 6x13 matrix. According to the documentation for bar
x values, specified as a vector or a matrix. If x and y are both vectors, then they must be equal length. If x and y are both matrices, then they must be equal size. If x is a vector and y is a matrix, then the length of x must equal the number of rows in y.
So your length for x must be 6 and not 13 if you wish it to work with the provided data. Or, perhaps you can transpose P as
bar(i,P');
  3 commentaires
Geoff Hayes
Geoff Hayes le 23 Fév 2016
kaylani - what does the data of P correspond to that it must be a 6x13 matrix? What are you expecting your histogram to look like given the dimensions of this matrix and of your i?
kalyani ohri
kalyani ohri le 26 Fév 2016
Thanks so much sir...I am getting the graph opposite to that i want sir....Any suggestion which can help me.....

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Data Distribution Plots dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by