1。语法错误,缺少很多end。2。大小写不分,比如开始用大写OP,后面用小写op。3。xor函数使用错误。4。matlab里没有nand函数。
运行结果是
Is X1 true of false?["true"/"false"]true
Is X2 true of false?["true"/"false"/" "]false
What is the operation?["and"/"or"/"nand"/"xor"/"not"]xor
true
程序档腊是
function baidu_logicaloperation
X1=input('Is X1 true of false?["true"培数/"false"]','s')
a=strcmpi(X1,'true')
%Get to know whether X1 is true of false
X2=input('Is X2 true of false?["true"/"false"/" "]','s')
if isempty(X2)
X='true'
else b=strcmpi(X2,'true')
%Get to know whether X2 is true of false
op=input('What is the operation?["and"/"or"/"nand"/"xor"/"not"]','s')
if strcmpi(op, 'and')
c=(a&b)
else if strcmpi(op, 'or')
c=(a|b)
else if strcmpi(op, 'xor')
c=xor(a,b)
else if strcmpi(op, 'not')
c=~a
end
end
end
end
end
if c==0
X='false'
else X='true'
end
%doing logical operation calculation
disp(X)
% 对向量a,b卷积,竖乘法La = length(a)
Lb = length(b)%向量槐渗早铅雀长喊悄度
c = zeros(Lb,La)
for i = 1:Lb
c(i,:) = a*b(Lb+1-i)
end
d = [zeros(Lb,Lb-1) c]
for i = 2:Lb
d(i,:) = [d(i,i:end) zeros(1,i-1)]
end
d = sum(d)
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)