Matrix must be square

function Proses_CC_Callback(hObject, eventdata, handles)
% hObject handle to Proses_CC (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
load data_x x;
load data_i i;
load data_p p;
load data_l l;
xbar=mean(x);
ibar=mean(i);
pbar=mean(p);
lbar=mean(l);
C1=sum(x-xbar)*(i-ibar)/(sum((x-xbar)^2)*sum(i-ibar)^2)^1.5;
C2=sum(x-xbar)*(p-pbar)/(sum((x-xbar)^2)*sum(p-pbar)^2)^1.5;
C3=sum(x-xbar)*(l-lbar)/(sum((x-xbar)^2)*sum(l-lbar)^2)^1.5;
%C1=(sum((x-xbar)*(i-ibar)))/((sum(x-xbar)^2)*(sum(i-ibar)^2)^1.5);
%C2=(sum((x-xbar)*(p-pbar)))/((sum(x-xbar)^2)*(sum(p-pbar)^2)^1.5);
%C3=(sum((x-xbar)*(l-lbar)))/((sum(x-xbar)^2)*(sum(l-lbar)^2)^1.5);
minimum = min([C1 C2 C3]);
if (C1 == minimum)
class = 'temuireng'
else if (C2 == minimum)
class = 'temuputih'
else (C3 == minimum)
class = 'temulawak'
end
set(handles.minimum, 'string',[ 'rimpang:' , num2str(class)]);
end
can help me? in the command window appears:
??? Error using ==> mpower
Matrix must be square.
Error in ==>
One_Minus_CC_new>Proses_CC_Callback at 267
C1=sum(x-xbar)*(i-ibar)/(sum((x-xbar)^2)*sum(i-ibar)^2)^1.5;

 采纳的回答

Matt Fig
Matt Fig 2012-10-23
编辑:Matt Fig 2012-10-23
Did you mean to take the element-by-element power of the arrays? Look at the difference:
x = magic(2) % A 2-by-2 matrix, for example.
x^2 % No dot, equivalent to x*x, need to have square matrix.
x.^2 % Note the dot (.) Need not be a square matrix.
So in your code you use (^2) instead of (.^2), is that what you meant to do?

2 个评论

C1, C2, C3 is the formula of the distance function correlation coefficient method. and i have changed:
C1=sum(x-xbar)*(i-ibar)/(sum((x-xbar).^2)*sum(i-ibar).^2)^0.5;
C2=sum(x-xbar)*(p-pbar)/(sum((x-xbar).^2)*sum(p-pbar).^2)^0.5;
C3=sum(x-xbar)*(l-lbar)/(sum((x-xbar).^2)*sum(l-lbar).^2)^0.5;
but in the command window appears:
??? Error using ==> eq
Matrix dimensions must agree.
Error in ==>
One_Minus_CC_new>Proses_CC_Callback at 275
if (C1 == minimum)
and I have improved the code:
minimum = min([C1 C2 C3]);
become:
minimum = 1-(abs([C1 C2 C3]);
but all the same error

请先登录,再进行评论。

更多回答(0 个)

类别

帮助中心File Exchange 中查找有关 Matrix Indexing 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by