Borrar filtros
Borrar filtros

matlab return the output of wrong function

2 visualizaciones (últimos 30 días)
xueqi
xueqi el 28 de En. de 2013
Hi fellows,
I have encounted a super weird situation. I will try to explain it clearly.
I have defined several function, one of them is called maxmin.m. And this function would call another function called maxmin0. But when i call the function maxmin, the result is always the result from the function maxmin0. I don't know where is the problem. Becasue maxmin.m return the proper result when I test it by get rid of function form and run it as a normal .m file.
Please help me about this. This is the code for maxmin.m
if true
%
function [ PF ] = maxmin(sub,DD) %risk parameter and low bounds
d1=DD(:,1:3)-1;
d2=DD(:,4:6)-1;
edw=DD(:,7);
rn=size(d1,1);
lb1=sub(1);
lb2=sub(2);
lb3=sub(3);
r=sub(4);
[PF0,eu0]=maxmin0(sub,DD);
[PF1,eu1]=maxmin1(sub,DD);
[PF2,eu2]=maxmin2(sub,DD);
[PF3,eu3]=maxmin3(sub,DD);
[PF4,eu4]=maxmin4(sub,DD);
[PF5,eu5]=maxmin5(sub,DD);
[PF6,eu6]=maxmin6(sub,DD);
for i=1:rn
eutotal(i,:)=[eu1(i);eu2(i);eu3(i);eu4(i);eu5(i);eu6(i)];
if (0<=PF0(i,1))<=edw(i) && 0<=PF0(i,2)<=edw(i)
PF(i,:)= PF0(i,:);
else
if(eu1(i)==max(eutotal(i)))
PF(i,:)=PF1(i,:);
elseif(eu2(i)==max(eutotal(i)))
PF(i,:)=PF2(i,:);
elseif(eu3(i)==max(eutotal(i)))
PF(i,:)=PF3(i,:);
elseif(eu4(i)==max(eutotal(i)))
PF(i,:)=PF4(i,:);
elseif(eu5(i)==max(eutotal(i)))
PF(i,:)=PF5(i,:);
elseif(eu6(i)==max(eutotal(i)))
PF(i,:)=PF6(i,:);
end
end
end
end
end
  1 comentario
xueqi
xueqi el 28 de En. de 2013
I am a little concerned about the way I define the output PF. It seems that matlab doesnt restore it...If I write maxmin as the m file form instead of function form, PF shows in the workspace and it is the right result. But if I call function maxmin, it returns the result from the function maxmin0.

Iniciar sesión para comentar.

Respuesta aceptada

Image Analyst
Image Analyst el 28 de En. de 2013
Perhaps it is because you seem to type with so many errors that it doesn't know whether you mean maxmim, maxmin1, or maxmim1 - all of which you referred to. In addition you misspelled "weird" as "wired", "don't" as "dont", and "because" as "becasue", so I don't have any confidence that you aren't continuing your history of typographical errors in your code. Please make sure everything in your code is spelled exactly as it should be.
  2 comentarios
xueqi
xueqi el 28 de En. de 2013
Editada: xueqi el 28 de En. de 2013
HI thanks for pointing out my typos. I am quite embarrassed about that. But I don't think this the problem comes from...
Image Analyst
Image Analyst el 28 de En. de 2013
This is not proper syntax:
if (0<=PF0(i,1))<=edw(i) && 0<=PF0(i,2)<=edw(i)
You need something like:
if 0<=PF0(i,1) && PF0(i,1)<=edw(i) && 0<=PF0(i,2) && PF0(i,2)<=edw(i)

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Just for fun en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by