# heat map error y values must equal number of rows in colordata

14 views (last 30 days)
Sebastian Sunny on 9 Dec 2021
Edited: Stephen23 on 10 Dec 2021
hi, i've been struggling to plot a heat map on matlab and i keep getting this error'
Stephen23 on 10 Dec 2021
heat map error y values must equal number of rows in colordata
hi, i've been struggling to plot 3 heat maps on matlab and i keep getting this error' Number of y values must equal the number of rows in 'ColorData'.
h1 = heatmap(k,Cd,Turbinepower);
how would i fix this?
clear all
close
figure;
deltaT = 0.01;
time = 0:deltaT:300;
k=6*10.^(1:10);
Cd=1.5*10.^(1:8);
%preallocation
turbinePowerMean = zeros(length(k),length(Cd));
turbinePowerStd = zeros(length(k),length(Cd));
%------------------Do not edit these lines---------------------------------
windTimeSeries = wblrnd(13,2.10,size(time'));
windTimeSeries = medfilt1(windTimeSeries,50,'truncate');
%-------------------------------------------------------------------------
for i = 1:length(k)
for j = 1:length(Cd)
data = windTurbineModel(windTimeSeries,Cd(j),deltaT,time,k(i));
turbinePowerMean(j,i) = mean(data);
turbinePowerStd(j,i) = std(data);
end
end
Turbinepower = turbinePowerMean/7000;
TurbineSTD = turbinePowerStd/7000;
meanSTD = turbinePowerMean./turbinePowerStd;
%plotting
subplot (1,3,1)
h1 = heatmap(k,Cd,Turbinepower);
xlabel('Generator control gain, k')
ylabel('Damping coeff kg m^2 s^-1')
title('Mean Power Output for varying k and c' )
subplot(1,3,2)
h2 = heatmap(k(i),Cd,TurbineSTD);
xlabel('Generator control gain, k')
ylabel('Damping coeff kg m^2 s^-1')
title('std Power Output for varying k and c' )
subplot (1,3,3)
h3 = heatmap(k,Cd,meanSTD);
xlabel('Generator control gain, k')
ylabel('Damping coeff kg m^2 s^-1')
title('mean/std Output for varying k and c' )
functions:
function turbinePower = windTurbineModel(WindSpeeds,Cd,deltaT,time,k)
%vairables defined
Cp = 0.335;
Ct = 0.042;
Vrated = 11.5; %m/s
Vcutin = 3; %m/s
Vcutout = 25; %m/s
D = 171;
j = 100e5;
%preallocation
rotorTorque = zeros(length(WindSpeeds),1); %Nm
turbinePower = zeros(length(WindSpeeds),1);
generatorTorque = zeros(length(WindSpeeds),1);
omegaRotor = zeros(length(WindSpeeds),1);
%eulers method
for i = 2:length(time)
rotorTorque(i) = windTurbineRotorModel(WindSpeeds(i),Ct,D,Vcutout,Vrated,Vcutin);
omegaRotor(i) = omegaRotor(i-1)+deltaT*(rotorTorque(i)-generatorTorque(i-1)-(Cd*(omegaRotor(i-1))))/j;
turbinePower(i) = omegaRotor(i)*rotorTorque(i);
generatorTorque(i) = k * omegaRotor(i).^2;
end
plot(WindSpeeds,turbinePower/1000)
ylabel('TurbinePower kW')
hold on
yyaxis right
plot(WindSpeeds,generatorTorque/1000)
hold on
plot(WindSpeeds,rotorTorque/1000)
end
function2 :
function [rotorTorque] = windTurbineRotorModel(WindSpeeds,Ct,D,Vcutout,Vrated,Vcutin)
if (WindSpeeds < Vcutin)
rotorTorque = 0;
elseif all(WindSpeeds >Vcutin) && all(WindSpeeds <=Vrated)
rotorTorque = (Ct)*(1/2)*(1.23)*pi*((D/2)^3)*WindSpeeds^2;
elseif all(WindSpeeds >Vrated) && all(WindSpeeds <= Vcutout)
rotorTorque = (Ct)*(1/2)*(1.23)*pi*((D/2)^3)*Vrated^2;
else
rotorTorque = 0;
end
end

Voss on 9 Dec 2021
Edited: Voss on 9 Dec 2021
The problem is that turbinePowerMean and turbinePowerStd are initialized to be 10-by-8 matrices here:
turbinePowerMean = zeros(length(k),length(Cd));
turbinePowerStd = zeros(length(k),length(Cd));
but then the i,j loops calculate and store the elements of those matrices with the indices reversed (leading to incorrectly sized matrices). Since you want k to be x in the heatmap (and Cd corresponds to y), the thing to do is this:
turbinePowerMean = zeros(length(Cd),length(k));
turbinePowerStd = zeros(length(Cd),length(k));