I am having problem converting this to Matlab. It either spits out 'char' as the answer or it would say untitled after i have written it in Matlab and fixed all the errors. Help me out.
2 次查看(过去 30 天)
显示 更早的评论
import itertools
class Armstrong:
def __init__(self, inputF, inputDf, outputF, outputDf, FloMin, FloMax):
self.inputF = inputF
self.inputDf = inputDf
self.outputF=outputF
self.outputDf=outputDf
self.FloMin=FloMin
self.FloMax=FloMax
def productOfMultiplexers(self):
return (self.outputDf/float(self.inputDf))
def primeFactors (self):
n=self.productOfMultiplexers()
I={2:0, 3:0, 5:0, 7:0, 11:0}
for i in I.keys():
while n%i==0:
I[i]+=1
n=n/i
return (I)
def MultiplierCombinaitons(self):
I=self.primeFactors ()
Ilist=[i for i in I.keys() for j in range(I[i])]
stuff = Ilist
productList=[]
for L in range(0, len(stuff)+1):
for subset in itertools.combinations(stuff, L):
product=1
for i in subset:
product=i*product
productList.append(product)
return (sorted(set(productList)))
def bestMatch(self):
case1=case.outputF- case.productOfMultiplexers() * case.inputF
case2=-case.outputF +case.productOfMultiplexers() * case.inputF
case3=case.outputF +case.productOfMultiplexers() * case.inputF
for M2 in case.MultiplierCombinaitons():
for c in [case1,case2,case3]:
if c>0 and c/M2 < case.FloMax and c/M2>case.FloMin:
return(M2,c/M2)
0 个评论
回答(1 个)
Dhananjay Kumar
2019-12-3
编辑:Dhananjay Kumar
2019-12-3
I suppose this is python code.
For converting this code to matlab code, you should understand the code completely and manually code it in MATLAB.
Instead of converting the code to matlab, you can call it directly from MATLAB.
See this: Call Python function from MATLAB
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Call Python from MATLAB 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!