RESHAPE command in MATLAB
2 次查看(过去 30 天)
显示 更早的评论
I am working on this piece of code which is basically k-means clustering and I'm really stuck at a point where cell needs to be reshaped into matrix:
vec_dist(i)=dist(s(i),reshape(cell2mat(codebook),L,length(codebook)));
with error: Error using reshape To RESHAPE the number of elements must not change.
Any help would be highly appreciated.
0 个评论
回答(1 个)
Matt J
2013-4-23
Do you understand why the following example produces an error? The error your code gives is due to the same thing.
>> reshape(rand(2,3),5,1)
Error using reshape
To RESHAPE the number of elements must not change.
5 个评论
Matt J
2013-4-23
Did you understand the example I posted? The error you're getting pertains to the sizes and values of the arguments, not their data type.
By entering the values of L and length(codebook), RESHAPE expects that the array you're trying to reshape has L*length(codebook) elements in it. That is apparently not the number of elements in the array cell2mat(codebook). If this surprises you, use DBSTOP as I suggested to see how many elements there actually are.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!