why msgbox for input make the code no response

1 次查看(过去 30 天)
hi,
whhy when create msgbox for input value within code , the window of input is not responding. But I used it in other function , it is work.
thanks

回答(2 个)

Image Analyst
Image Analyst 2014-3-2
msgbox's only input is a string that it displays to the user. It does not accept input from the user, only from the programmer. If you want to accept input from the user, use questdlg() or inputdlg().
  4 个评论
Image Analyst
Image Analyst 2014-3-2
Try this code:
% Ask user for a number.
defaultValue = 45;
titleBar = 'Enter a value';
userPrompt = 'Enter the integer';
caUserInput = inputdlg(userPrompt, titleBar, 1, {num2str(defaultValue)});
if isempty(caUserInput),return,end; % Bail out if they clicked Cancel.
% Round to nearest integer in case they entered a floating point number.
integerValue = round(str2double(cell2mat(caUserInput)));
% Check for a valid integer.
if isnan(integerValue)
% They didn't enter a number.
% They clicked Cancel, or entered a character, symbols, or something else not allowed.
integerValue = defaultValue;
message = sprintf('I said it had to be an integer.\nI will use %d and continue.', integerValue);
uiwait(warndlg(message));
end
nada ali
nada ali 2014-3-2
thanks , but the problem is still, I will show u the my code. the following function works well if I run it wuthout call. but when I call it from another program , the code is not response.
function n=Association_Rules3(f2)
clc
support_ant_cons(1,1)=struct('item',[0]);
No_cluster=2;act_u=1;active_cluster=0;kkk=1;sum_uniq=[];
f1=dlmread('d:\pr\netflix\total_final.txt');
f2=dlmread('d:\pr\netflix\new\group2.txt');
eval_item=dlmread('d:\pr\netflix\eval_map.txt');
[filename1,filepath1]=uigetfile({'*.txt*','Text Files'},...
'Select Data File 1');
cd(filepath1);
target_user= dlmread(filename1);
%N_top=input('the size of recommendation list:');
defaultValue = 45;
titleBar = 'Enter a value';
userPrompt = 'Enter the length of recommendation list';
caUserInput = inputdlg(userPrompt, titleBar, 1, {num2str(defaultValue)});
if isempty(caUserInput),return,end; % Bail out if they clicked Cancel.
% Round to nearest integer in case they entered a floating point number.
N_top = round(str2double(cell2mat(caUserInput)));
% Check for a valid integer.
if isnan(N_top)
% They didn't enter a number.
% They clicked Cancel, or entered a character, symbols, or something else not allowed.
N_top = defaultValue
message = sprintf('I said it had to be an integer.\nI will use %d and continue.', integerValue);
uiwait(warndlg(message));
end
No_cluster=2;act_u=1;active_cluster=0;kkk=1;sum_uniq=[];
for no=1:No_cluster
switch no
case 1
f0=dlmread('d:\pr\netflix\Association_Rules\communities\table1_two_duration.txt');
case 2
f0=dlmread('d:\pr\netflix\association_rules\communities\newtab_two_duration.txt');
end
clear precis_recall;
clear accuracy;
clear relevant_item;
[p o]=size(f0);r=1;
% cc=(f2(no,:));
% cc=cc(cc~=0);
% L=length(cc);
% %[p o]=size(f2);
% [p o]=size(f0);r=1;
% k=1;
xxx=f2(no,:);
% xxx1=group(no,:);
xxx=xxx(xxx~=0);
% xxx1=xxx1(xxx1~=0);
% L=length(xxx);
tt= intersect(xxx,target_user);
% if L==1
% f0(2,1:o)=0;
% end
support_ant=sum(f0); BB=1;
for i=1:length(tt)%%%for each user create rules
clear idx;
clear dd;
clear recom_list;
clear support_ant_cons;
clear confidence;
clear confidence_rule;
dd=1;
aaa=i%find(f2(no,:)==tt(i));
x=f0(aaa,:);
for j=1:o
if x(j)==0
idx(dd)=j;
dd=dd+1;
end
end
for g=1:length(idx)
j1=1;
for j=1:o
if f0(aaa,j)==1
d1=0;
for k=1:p
if f0(k,j)==1 & f0(k,idx(g))==1
d1=d1+1;
end
end
d1;
support_ant_cons(aaa,j).item(g)=d1;
confidence(j1)=(support_ant_cons(aaa,j).item(g)/support_ant(j));
j1=j1+1;
else
continue;
end
end
confidence_rule(aaa,g)=max(confidence(1:j1-1));
item(aaa,g)=idx(g);
end
%N_top=15;
length(idx);
[recomm ind1]=sort(confidence_rule(aaa,:),'descend');
if length(idx)>=N_top
%if ~isempty(length(idx)
recom_list(aaa,1:N_top)=item(aaa,ind1(1:N_top));
%recom_list(aaa,1:length(idx))=item(aaa,ind1(1:length(idx)));
ss=recom_list(aaa,:);
ss=ss(ss~=0);
aa(aaa,1:length(ss))=ss;
clear idx;
% f2=unique(f1);
% f2=f2(f2~=0);
[m n]=size(eval_item);
% buf=recom_item(i,:);
%x=f1(f2(no,i),:);
x1=f1(tt(i),:);
x1=x1(x1~=0);
unique_x=unique(x1);
% if length(unique_x)>=15
% size(unique(x));
% continue;
% end
%%%update evalution priod
%z=eval_item(f2(no,i),:);
z=eval_item(tt(i),:);
z=z(z~=0);
z=unique(z);
t=1;
%evaluation=eval_item(f2(No_cluster,i),:);
evaluation=[];
for v=1:length(z)
a1=find(unique_x==z(v));
if isempty(a1)
evaluation(t)=z(v);
t=t+1;
end
end
if length(evaluation)>=1
%zzz(kkk)=f2(no,i);
list(kkk,1:length(ss))=ss;
kkk=kkk+1;
k=1;
% d1=f1(f2(No_cluster,i),:);
% u=unique(d1);
% uniqu_d=u(u~=0);
h=1;
% v=[1 3 4 5 6 7 8 9 10 11 12 13 15 16 17 18 19];
for v=1:26
%if v~=2 & v~=14
b2=find(unique_x==v);
if isempty(b2)
relevant_item(aaa,h)=v;
h=h+1;
end
% end
end
% relevant=setdiff(v,unique_x);
% relevant_item(aaa,1:length(relevant))=relevant;
r1=relevant_item(aaa,:);
relevant_item_len=r1(r1~=0);
eval=evaluation;
eval=eval(eval~=0);
recom2=recom_list(aaa,:);
recom2=recom2(recom2~=0);
d=intersect(recom2,eval);
%q1=intersect(recom_list(i,:),eval_item(i,:));
r=1;
for zz=1:length(recom2)
a1=find(d==recom2(zz));
if isempty(a1)
b(r)=recom2(zz);
r=r+1;
end
end
%b=setdiff(recom2,d);
if r==1%isempty(b)
b=[];
end
if t==1
c=[];
pc=0;
relv1=relevant_item(aaa,:);
relv1=relv1(relv1~=0);
recom1=recom_list(aaa,:);
recom1=recom1(recom1~=0);
[buf buf1]=intersect(relv1,recom1);
for m1=1:length(buf)
r1(buf1(m1)-pc)=[];
pc=pc+1;
end
a=r1(r1~=0);
else
xx=evaluation;
xx=xx(xx~=0);
xx=unique(xx);
%buf=intersect(xx,recom_list(i,:));
r2=1;
for zz=1:length(xx)
a1=find(d==xx(zz));
if isempty(a1)
c(r2)=xx(zz);
r2=r2+1;
end
end
%c=setdiff(xx,d);
if r2==1%isempty(c)
c=[];
end
%buf=intersect(relevant_item(i,:),recom_list(i,:));
r1;
pc=0;
relv=relevant_item(aaa,:);
relv=relv(relv~=0);
recom=recom_list(aaa,:);
recom=recom(recom~=0);
[buf buf1]=intersect(relv,recom);
for k=1:length(buf)
r1(buf1(k)-pc)=[];
pc=pc+1;
end
pc=0;
eval2=evaluation;
eval2=eval2(eval2~=0);
[buf0 buf2]=intersect(r1,eval2);
for zz=1:length(buf0)
r1(buf2(zz)-pc)=[];
pc=pc+1;
end
a=r1(r1~=0);
end
%end%%if of cmp_nempty
a=a(a~=0);
b=b(b~=0);
c=c(c~=0);
d=d(d~=0);
par_confusion(BB,1)=length(a);
par_confusion(BB,2)=length(b);
par_confusion(BB,3)=length(c);
par_confusion(BB,4)=length(d);
len{no}(i,1)=length(a);
len{no}(i,2)=length(b);
len{no}(i,3)=length(c);
len{no}(i,4)=length(d);
accuracy(BB)=(length(a)+length(d))/(length(a)+length(b)+length(c)+length(d));
precis_recall(BB,1)= length(d)/(length(b)+length(d));
precis_recall(BB,2)=length(d)/(length(d)+length(c));
Fallout(BB)=length(b)/(length(b)+length(a));
BB=BB+1;
clear b;
clear d;
clear c;
clear a;
end
end
end
end

请先登录,再进行评论。


Image Analyst
Image Analyst 2014-3-2
Not sure what that means and I didn't run the code. But if you want a response from a message box presented to the user, you're going to have to use questdlg() instead of msgbox().
  2 个评论
nada ali
nada ali 2014-3-3
but the questdlg gives choices, but I want input numerical value
Image Analyst
Image Analyst 2014-3-3
You can either use inputdlg(), input(), or write your own GUI.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Dialog Boxes 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by