【问题标题】:startswith from python to octave从python开始到八度
【发布时间】:2016-12-14 21:05:06
【问题描述】:

我有一个 python 代码,想用 Octave 编写一个相同的代码,但是有些命令我从未在 octave 中找到它们。有一部分代码我没看懂,就是这个函数:

def CVangles(theta, geo, key):

"""
Parameters
    ----------
    theta : float
        The crank angle, between 0 and 2*pi
    geo : struct
        The structure with the geometry obtained from get_geo()
    key : string
        The name of the involute to be considered

   """

     CV = struct()
     CV.Outer = struct()
     CV.Inner = struct()
     if key.startswith('c1.'):
         alpha = int(key.split('.')[1])
         CV.Outer.involute = INVOLUTE_FI
         CV.Outer.phi_0 = geo.phi_fi0       
     return CV

如何在八度音阶中用startswith和split来表达

【问题讨论】:

    标签: python python-2.7 octave


    【解决方案1】:

    您可以使用strncmpkey 的前3 个字符与'c1.' 进行比较

    if strncmp(key, 'c1.', 3)
    

    此外,您可以使用strsplit 代替split 将字符串拆分为'.' 字符处的片段。

    alpha = strsplit(key, '.'){2};
    

    【讨论】:

    • 谢谢 Suever 我有无穷无尽的问题 :),你的帮助让我很高兴,而且很有用....我现在可以问下一个问题吗 :) stackoverflow.com/questions/41158385/…
    • 它完成了......你能看看我在上面的lenk中的下一个问题吗?
    猜你喜欢
    • 1970-01-01
    • 2018-06-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-12
    • 2017-03-06
    • 2012-11-23
    相关资源
    最近更新 更多