Colordata Error in Heatmap

I am using heatmap like this:
FigureGenerated = heatmap(x_axis_val,y_axis_val,capture_status,'Colormap',mymap);
saveas(FigureGenerated,Path_Capture_Status);
where x_axis_val (1st column) and y_axis_val (2nd column) are created as per user input. And capture_status contains all values of the 5th column of the same matrix.
The code works fine sometimes, but at other times I get the following error:
Error using heatmap (line 53)
Number of x values must equal the number of columns in
'ColorData'.
How can this be solved?
Please help. Thanks a lot.

Respuestas (1)

Ameer Hamza
Ameer Hamza el 14 de Oct. de 2020

1 voto

It means that if the dimensions are
n = numel(x_axis_val)
m = numel(y_axis_val)
Then the dimensions of capture_status should be m*n.

5 comentarios

Komal Shah
Komal Shah el 15 de Oct. de 2020
Thank you for the response Ameer!
I have used it that way. The variables have been defined in the following manner in the code:
x_axis_val = xpos1:x_spac:xpos2;
y_axis_val = ypos2:(-y_spac):ypos1;
capture_status = zeros(numel(y_axis_val),numel(x_axis_val));
where xpos1 is the minimum value of x entered by the user, and xpos2 the maximum. Similarly for ypos1 and ypos2. The x_spac and y_spac are variables to hold a predefined value for spacing.
The user input is taken right at the beginning, before defining & declaring these variables. But since x_axis_val and y_axis_val depend on the user input, is it possible that the number of elements change during the execution?
Ameer Hamza
Ameer Hamza el 15 de Oct. de 2020
These lines seems to work fine if the values are pre-defined
xpos1 = 1;
xpos2 = 10;
ypos1 = 7;
ypos2 = 3;
x_spac = 1;
y_spac = 1;
x_axis_val = xpos1:x_spac:xpos2;
y_axis_val = ypos2:(-y_spac):ypos1;
capture_status = zeros(numel(y_axis_val),numel(x_axis_val));
heatmap(x_axis_val, y_axis_val, capture_status)
Komal Shah
Komal Shah el 15 de Oct. de 2020
Yes. Sometimes they work fine even with user input. At other times they do not.
The only thing changing with each execution is user input. I'm not able to understand how that has an effect on the code.
But thank you for your inputs.
Ameer Hamza
Ameer Hamza el 15 de Oct. de 2020
You can use the breakpoints: https://www.mathworks.com/help/matlab/matlab_prog/set-breakpoints.html to find the error.
Komal Shah
Komal Shah el 15 de Oct. de 2020
Thank you, I will try this.

Iniciar sesión para comentar.

Etiquetas

Preguntada:

el 14 de Oct. de 2020

Comentada:

el 15 de Oct. de 2020

Community Treasure Hunt

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

Start Hunting!

Translated by