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 日

0 投票

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 件のコメント

Dian Permatasari
Dian Permatasari 2012 年 10 月 23 日
編集済み: Dian Permatasari 2012 年 10 月 23 日
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)
Dian Permatasari
Dian Permatasari 2012 年 10 月 23 日
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 ExchangeMatrix Indexing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by