请帮我修订一下一个很简单的Matlab程序

请帮我修订一下一个很简单的Matlab程序,第1张

我没分析你的构思,只配蠢首是改了你的程序,现在可以用了。主要错误是:

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)


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/8280351.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-15
下一篇 2023-04-15

发表评论

登录后才能评论

评论列表(0条)

保存