Borrar filtros
Borrar filtros

Error when calling function from GUI

1 visualización (últimos 30 días)
eng keong
eng keong el 19 de Feb. de 2012
Editada: Azzi Abdelmalek el 16 de Oct. de 2013
This happens when i assigned calling of the function from a gui. It operated fine if i just simply call the function in command line.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
case 'Correlation',
disp(sCr(i,j))
disp(CrVa)
k=sCr(i,j)-CrVa
the computation gives:
0.5616
0.9988
k =
-47.4384 -45.4384 -56.4384 -56.4384 -55.4384 -55.4384
0.5491
0.9988
k =
-47.4509 -45.4509 -56.4509 -56.4509 -55.4509 -55.4509
%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1 comentario
Image Analyst
Image Analyst el 19 de Feb. de 2012
Why was sCr(i,j) not printed out in the second case??? Also, can you print out more decimal places, in case there are differences beyond 4 decimal places:
fprintf('%.9f\n', sCr(i,j));

Iniciar sesión para comentar.

Respuesta aceptada

eng keong
eng keong el 21 de Feb. de 2012
Ok, i've found the error. Values stored as string won't be automatically treated as numbers sometimes.
0.9988 --> 6 ascii values hence when i use a number deduct string 0.9988, array of values appeared.
Thanks and case closed. Sorry for wasting time of those who tried to help.
Thanks alot.

Más respuestas (2)

eng keong
eng keong el 19 de Feb. de 2012
thanks for replying. After fprintf('%.9f\n', sCr(i,j)); i got
0.561589812
0.9988
k =
-47.4384 -45.4384 -56.4384 -56.4384 -55.4384 -55.4384
0.549092535
0.9988
k =
-47.4509 -45.4509 -56.4509 -56.4509 -55.4509 -55.4509
  3 comentarios
eng keong
eng keong el 19 de Feb. de 2012
the calculation is wrong 0.5615-0.9988=-0.4374 and it should be a single value instead of array of values. Sorry that i didn't make it clear.
eng keong
eng keong el 19 de Feb. de 2012
the error message leads to latter part of the code which is due to lack of data because i've set the criteria that the sCr must be bigger than CrVa in order to be stored. The error is tracked back to the part as stated above which gives wrong calculation
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0.549092535
0.9988
k =
-47.4509 -45.4509 -56.4509 -56.4509 -55.4509 -55.4509
??? Index exceeds matrix dimensions.
Error in ==> uniq at 2
v=nnz(Cll(1,:));
.
.
.
%%%%%%%%%%%%%%%%%%%%
this is how the display like when i just call the function through command line
0.6152
0.9988
-0.3836
0.5684
0.9988
-0.4304
* note that i've removed k, and displaying only sCr(i,j)-CrVa

Iniciar sesión para comentar.


Image Analyst
Image Analyst el 19 de Feb. de 2012
Do you know how to use the debugger? Can you put a breakpoint there and hover over each of the terms in your k line and tell me it they are .56 and .9988? Chances are that CrVa is not a single number with value .9988 and that it is an array, and that you are not posting your full code.
  2 comentarios
eng keong
eng keong el 19 de Feb. de 2012
sorry i don't know how to use debugger
and my gui comprise of a few other guis as i'm really a beginner only.
clust(M,'Correlation',0.9988,3)%%command line
function data_out=clust(data_in,algo,thres,val)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Correlation
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
switch algo
case 'Correlation',[v,p,Cr]=corrmat(data_in);
case 'Euclidean',[v,p,Cr]=eucmat(data_in);
end
[sCr,indi] = sort(Cr,'descend');
[Cll]=ver(thres,v,sCr,indi,algo);
.
.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function[v,p,Cr]=corrmat(M)
[v,p]=size(M);
Cr=ones(v,1)./2;
Cr=diag(Cr);
for j=1:1:v-1
i=j+1:1:v;
Cr(i,j)=1-pdist2(M(i,:),M(j,:),'correlation');
end
Cr=Cr+Cr';
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function[data_out]=ver(CrVa,v,sCr,indi,algo)
a=1;c=0;Cll=zeros(v,v);
for j=1:1:v
chkr=zeros(v,1);
for i=1:1:v;
b=1;
switch algo
case 'Correlation',
disp(sCr(i,j))
disp(CrVa)
disp(sCr(i,j))
if sCr(i,j)>=CrVa
chkr(indi(i,j),1)=1;
end
case 'Euclidean',
if sCr(i,j)<=CrVa
chkr(indi(i,j),1)=1;
end
end
end
if sum(chkr(:,1))>1
for i=1:1:v;
if chkr(i,1)==1
Cll(b,a)=i;
b=b+1;
end
end
a=a+1;
if (b-1)>c
c=b-1;
end
end
end
data_out=trimmer(Cll,c,a-1);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function data_out=trimmer(data_in,b,a)
data_out=zeros(b,a);
for i=1:a
for j=1:b
data_out(j,i)=data_in(j,i);
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
M =
5.1000 3.5000 1.4000 0.2000
4.9000 3.0000 1.4000 0.2000
4.7000 3.2000 1.3000 0.2000
4.6000 3.1000 1.5000 0.2000
5.0000 3.6000 1.4000 0.2000
5.4000 3.9000 1.7000 0.4000
4.6000 3.4000 1.4000 0.3000
5.0000 3.4000 1.5000 0.2000
4.4000 2.9000 1.4000 0.2000
4.9000 3.1000 1.5000 0.1000
5.4000 3.7000 1.5000 0.2000
4.8000 3.4000 1.6000 0.2000
4.8000 3.0000 1.4000 0.1000
4.3000 3.0000 1.1000 0.1000
5.8000 4.0000 1.2000 0.2000
5.7000 4.4000 1.5000 0.4000
5.4000 3.9000 1.3000 0.4000
5.1000 3.5000 1.4000 0.3000
7.0000 3.2000 4.7000 1.4000
6.4000 3.2000 4.5000 1.5000
6.9000 3.1000 4.9000 1.5000
5.5000 2.3000 4.0000 1.3000
6.5000 2.8000 4.6000 1.5000
5.7000 2.8000 4.5000 1.3000
6.3000 3.3000 4.7000 1.6000
4.9000 2.4000 3.3000 1.0000
6.6000 2.9000 4.6000 1.3000
5.2000 2.7000 3.9000 1.4000
5.0000 2.0000 3.5000 1.0000
5.9000 3.0000 4.2000 1.5000
6.0000 2.2000 4.0000 1.0000
6.1000 2.9000 4.7000 1.4000
5.6000 2.9000 3.6000 1.3000
6.7000 3.1000 4.4000 1.4000
5.8000 2.7000 5.1000 1.9000
7.1000 3.0000 5.9000 2.1000
6.3000 2.9000 5.6000 1.8000
6.5000 3.0000 5.8000 2.2000
7.6000 3.0000 6.6000 2.1000
4.9000 2.5000 4.5000 1.7000
7.3000 2.9000 6.3000 1.8000
6.7000 2.5000 5.8000 1.8000
7.2000 3.6000 6.1000 2.5000
6.5000 3.2000 5.1000 2.0000
6.4000 2.7000 5.3000 1.9000
6.8000 3.0000 5.5000 2.1000
5.7000 2.5000 5.0000 2.0000
5.8000 2.8000 5.1000 2.4000
6.4000 3.2000 5.3000 2.3000
6.5000 3.0000 5.5000 1.8000
7.7000 3.8000 6.7000 2.2000
above is calling from command line and should work fine..
the error above is from the gui case..
below is what push button will trigger where data is stored in DATA.data...
tem, thres,val are already acquired from textboxes...
disp(tem)
disp(thres)
disp(val)
DATA.data=clust(DATA.data,tem,thres,val);
"Correlation
0.9988
3" is shown in command window
eng keong
eng keong el 19 de Feb. de 2012
hmm to clarify myself better, the data array M is my input data.. and i didn't know that i can write the whole gui in a single file so it would be very messy if posted.

Iniciar sesión para comentar.

Categorías

Más información sobre Large Files and Big Data en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by