Matrix must be square

6 Ansichten (letzte 30 Tage)
Dian Permatasari
Dian Permatasari am 23 Okt. 2012
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;

Akzeptierte Antwort

Matt Fig
Matt Fig am 23 Okt. 2012
Bearbeitet: Matt Fig am 23 Okt. 2012
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 Kommentare
Dian Permatasari
Dian Permatasari am 23 Okt. 2012
Bearbeitet: Dian Permatasari am 23 Okt. 2012
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 am 23 Okt. 2012
and I have improved the code:
minimum = min([C1 C2 C3]);
become:
minimum = 1-(abs([C1 C2 C3]);
but all the same error

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by