展开全部
假设你用GUI来编写,可以在GUI添加下面几个控制:两个编辑框,一个是用来给用户输入字符串,设其Tag为UserInput,另一个是用来给用记指定字母的,设其Tag为UserLetter,一个文本框用来显示结果的,设其Tag为Output,一个按键用来计算结果的,那么很简单的,你在按键的Callback函数里加入如下代码即可:
userinput = get(handles.UserInput,'String');
if ischar(userinput)
userletter = get(handles.UserLetter,'String')
if length(userletter)==0 || length(userletter) > 1%假设你想让用非空输入或只能输入一个字母
if (abs(userletter) >= 97 && abs(userletter) <=122) || (abs(userletter) >= 41 && abs(userletter) <=90)
num = sum(ismember(userinput,userletter)) ;
set(handles.Output,'String',num2str(num))
else
WarnDlg('your input is not a letter')
retrun
end
else
WarnDlg('the char string you input is wrong!')
return
end
else
WarnDlg('your input is not char string')
retrun
end
userinput = get(handles.UserInput,'String');
if ischar(userinput)
userletter = get(handles.UserLetter,'String')
if length(userletter)==0 || length(userletter) > 1%假设你想让用非空输入或只能输入一个字母
if (abs(userletter) >= 97 && abs(userletter) <=122) || (abs(userletter) >= 41 && abs(userletter) <=90)
num = sum(ismember(userinput,userletter)) ;
set(handles.Output,'String',num2str(num))
else
WarnDlg('your input is not a letter')
retrun
end
else
WarnDlg('the char string you input is wrong!')
return
end
else
WarnDlg('your input is not char string')
retrun
end
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
用到两个函数,input和strfind,运行我给你写的程序看一下:
temp1=input('what is your desired letter? >')
temp2=input('what is your string?>')
temp3=strfind(temp2,temp1)
numel(temp3)
下面是运行结果:
>> temp1=input('what is your desired letter? >') %询问用户,输入想要的字母,假设是a
what is your desired letter? >'a'
temp1 =
a
>> temp2=input('what is your string?>') %询问用户,输入想要的字符串,假设是what are you doing
what is your string?>'what are you doing now?'
temp2 =
what are you doing now?
>> temp3=strfind(temp2,temp1) %在字符串里找字母
temp3 =
3 6
>> numel(temp3) %统计有多少个,上面的字符串里有2个a
ans =
2
temp1=input('what is your desired letter? >')
temp2=input('what is your string?>')
temp3=strfind(temp2,temp1)
numel(temp3)
下面是运行结果:
>> temp1=input('what is your desired letter? >') %询问用户,输入想要的字母,假设是a
what is your desired letter? >'a'
temp1 =
a
>> temp2=input('what is your string?>') %询问用户,输入想要的字符串,假设是what are you doing
what is your string?>'what are you doing now?'
temp2 =
what are you doing now?
>> temp3=strfind(temp2,temp1) %在字符串里找字母
temp3 =
3 6
>> numel(temp3) %统计有多少个,上面的字符串里有2个a
ans =
2
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
syms x y;
f=2*x^2+3*x-5;
g=x^2-x+4;
h=f+g
h =
3*x^2+2*x-1
你需要定义参数变量,x,y,所有带参数的运算都需要先定义参数变量。
f=2*x^2+3*x-5;
g=x^2-x+4;
h=f+g
h =
3*x^2+2*x-1
你需要定义参数变量,x,y,所有带参数的运算都需要先定义参数变量。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询