Using clusterdata() to plot clusters using plot(). "Vectors must be the same length"

3 次查看(过去 30 天)
Hello, I am attempting to use the cluseterdata() function using this tutorial:
To plot clusters for my own dataset. Here is the code i've written so far:
data=file02;
rng('default')
dates=file02.Date;
x=dates;
y=[file02.Thermal,file02.Nuclear,file02.Hydro];
clusters=clusterdata(y,'maxclust',16,'distance','correlation','linkage','average');
display(clusters);
for c = 1:16
subplot(4,4,c);
plot(x,y((clusters == c),:)');
axis tight
end
The "dates" variable is a 4945x1 datetime table and the y variable is a 4945x3 double table. When i try to graph the clusters of this data, I get an error "Vectors must be the same length". I know that the length of cluster data at 'c' will be different for each iteration. But, the "x" variable will be of constant length 4095. I am curious on how to plot the clusters with the date being constant on the x axis?

回答(1 个)

Seth Furman
Seth Furman 2020-10-18
You'll need to decide what you want the x-values to be when y((clusters == c),:)' does not have 4095 elements.
I suspect you want something like the following.
plot(x(clusters == c),y((clusters == c),:)');

类别

Help CenterFile Exchange 中查找有关 Function Approximation, Clustering, and Control 的更多信息

产品


版本

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by