小编Jam*_*rtz的帖子

如何在MatLab中明智地组合两个大小相等的向量元素?

我有两个向量:

a = [1 3 5 7 9];
b = [2 4 6 8 10];
Run Code Online (Sandbox Code Playgroud)

我需要将元素结合在一起.这意味着我需要vector a的第一个元素,然后是vector b的第一个元素,b的第二个元素,b的第二个元素,依此类推,直到我得到以下结果:

combined = [1 2 3 4 5 6 7 8 9 10]
Run Code Online (Sandbox Code Playgroud)

我如何在MatLab中执行此操作?

编辑

我对前三个答案(Josh,Marc和Kronos)进行了测试,并比较了运行它们所花费的时间.在进行10次迭代预热后,我每跑100次.创建的向量长度完全相同(16e + 6),随机值范围为1到100:

Test Results
Test:           Total Time (100 runs):      Avg Time Per Exec:
Josh B          21.3687                     0.2137
Marc C          21.4273                     0.2143
Kronos          31.1897                     0.3119
Run Code Online (Sandbox Code Playgroud)

似乎Josh和Marc的解决方案在执行时间上都相似.

matlab vector

5
推荐指数
1
解决办法
1万
查看次数

如何在MATLAB中正确设置数值积分?

我想整合这个表达式:

正态分布函数:

但是我似乎在设置功能时遇到了问题.正如 MATLAB解释中所述,我已经定义了一个名为'NDfx.m'的独立函数,如下所示:

    function [ y ] = NDfx(x)

    y = (1/sqrt(2*pi))*exp(-.5*x^2); % Error occurs here

    end
Run Code Online (Sandbox Code Playgroud)

但是当我在我的main函数中调用它时,我在上面的注释行中收到错误.我的主要功能如下:

function[P] = NormalDistro(u,o2,x)

delta = x-u;
dev = abs((delta)/o2);           % Normalizes the parameters entered into function
P_inner = quad(@NDfx,-dev,dev);  % Integrates function NDfx from -dev to dev (error here)
P_outer = 1 - P_inner;           % Calculation of outer bounds of the integral

if delta > 0
    P = P_inner + (P_outer/2);

elseif delta < 0
    P = P_outer/2;

elseif dev == …
Run Code Online (Sandbox Code Playgroud)

matlab numerical-integration

4
推荐指数
1
解决办法
1762
查看次数

如何在wxpython中设置切换按钮的颜色?

我有一个已创建的按钮集合,需要在按下按钮时更改按钮的颜色。当前,它设置默认颜色(灰色=无效;浅蓝色=有效):

在此处输入图片说明

但我想将活动颜色更改为红色。

这是我的按钮类:

class ButtonClass(wx.Panel):
    def __init__(self, parent, name, id):
        wx.Panel.__init__(self, parent)
        self.name = name
        self.taskid = id

        self.button = wx.ToggleButton(self, 1, size=(50, 50))
        self.button.SetLabel('Start')

        self.mainSizer = wx.BoxSizer(wx.HORIZONTAL)
        self.mainSizer.Add(self.button)

        self.Bind(wx.EVT_TOGGLEBUTTON, self.toggledbutton, self.button)

    # Where the buttons change state
    def toggledbutton(self, event):

        # Active State
        if self.button.GetValue() == True:

            self.button.SetLabel('Stop')

        # Inactive State
        if self.button.GetValue() == False:

            self.button.SetLabel('Start')
Run Code Online (Sandbox Code Playgroud)

我已经尝试使用self.button.SetColourself.button.SetBackgroundColourself.button.SetForegroundColour所有这一切都没有成功。有没有办法在wxpython中完成此操作?

wxpython colors button togglebutton

4
推荐指数
1
解决办法
9026
查看次数

如何使用PySide将ProgressBar添加到StatusBar?

我想将进度条添加到应用程序的状态栏中。我发现了这篇文章,但是使用insertWidget()似乎没有用。

python statusbar pyside progress-bar

4
推荐指数
1
解决办法
3735
查看次数

如何使用Python在列表中转换多个列表?

我想在列表中转换多个列表?我正在使用循环,但每个子列表项之间没有逗号.

myList = [['a','b','c','d'],['a','b','c','d']]
myString = ''
for x in myList:
    myString += ",".join(x)
print myString
Run Code Online (Sandbox Code Playgroud)

输出继电器:

a,b,c,da,b,c,d
Run Code Online (Sandbox Code Playgroud)

期望的输出:

a,b,c,d,a,b,c,d
Run Code Online (Sandbox Code Playgroud)

python join nested-lists

4
推荐指数
2
解决办法
694
查看次数

Python中函数的数学集成

我正在尝试集成此功能:

在此输入图像描述

但是我遇到了以下错误:

Traceback (most recent call last):

  File "<ipython console>", line 1, in <module>

  File "siestats.py", line 349, in NormalDistro

    P_inner = scipy.integrate(NDfx,-dev,dev)

TypeError: 'module' object is not callable
Run Code Online (Sandbox Code Playgroud)

我的代码运行这个:

# Definition of the mathematical function:
def NDfx(x):

    return((1/math.sqrt((2*math.pi)))*(math.e**((-.5)*(x**2))))

# This Function normailizes x, u, and o2 (position of interest, mean and st dev) 
# and then calculates the probability up to position 'x'

def NormalDistro(u,o2,x):


    dev = abs((x-u)/o2)


    P_inner = scipy.integrate(NDfx,-dev,dev)

    P_outer = 1 - P_inner

    P = P_inner …
Run Code Online (Sandbox Code Playgroud)

python function scipy

3
推荐指数
1
解决办法
5223
查看次数

如何在Matlab中访问超类的常量属性?

我有一个简单的类结构,如下所示:

classdef super < hgsetget
    properties(Constant = true, Access = private)
        PROP1 = 1;
        PROP2 = {2 [3 4] [5 6]};
    end

    methods
        function self = super()
            // Constructor code here
            // ...
        end
    end
end
Run Code Online (Sandbox Code Playgroud)

然后由子类继承,如此.

classdef sub < super
    properties
        PROP3 = 7;
    end

    methods
        function self = sub()
            // Subclass constructor here
            // ...
            self = self@super();
            test = self.PROP1; // I don't appear to have access to PROP1 from Super

        end
    end
end
Run Code Online (Sandbox Code Playgroud)

我的问题是当我尝试访问超级的属性PROP1或者 …

oop matlab inheritance subclass superclass

3
推荐指数
1
解决办法
2031
查看次数

`&`运算符对标准逻辑向量做了什么?

我正在看一些执行以下操作的代码:

signal1 : std_logic
vector1 : std_logic_vector

vector1 <= vector1(20 downto 1) & signal1;
Run Code Online (Sandbox Code Playgroud)

我假设a vector1(20 downto 1)产生以下内容:

[20 19 18 ... 3 2 1]
Run Code Online (Sandbox Code Playgroud)

但我不明白的是&它的作用.它是否返回0if signal1is 0和创建的向量是否signal11

vhdl

3
推荐指数
1
解决办法
1039
查看次数

如何在PySide QFrame中自动拟合Matplotlib图?

我正在创建一个也使用MatPlotLib的简单PySide应用程序.但是,当我将图形添加到a中时QFrame,图形不会自动适合框架:

不自动伸展的情节

我的图表是使用以下代码创建的:

class GraphView(gui.QWidget):
    def __init__(self, name, title, graphTitle, parent = None):
        super(GraphView, self).__init__(parent)

        self.name = name
        self.graphTitle = graphTitle

        self.dpi = 100
        self.fig = Figure((5.0, 3.0), dpi = self.dpi, facecolor = (1,1,1), edgecolor = (0,0,0))
        self.axes = self.fig.add_subplot(111)
        self.canvas = FigureCanvas(self.fig)

        self.Title = gui.QLabel(self)
        self.Title.setText(title)

        self.layout = gui.QVBoxLayout()
        self.layout.addStretch(1)
        self.layout.addWidget(self.Title)
        self.layout.addWidget(self.canvas)
        self.setLayout(self.layout)

    def UpdateGraph(self, data, title = None):
        self.axes.clear()
        self.axes.plot(data)
        if title != None:
            self.axes.set_title(title)

        self.canvas.draw()
Run Code Online (Sandbox Code Playgroud)

它被添加到主Widget中,如下所示:

# Create individual Widget/Frame (fftFrame)
        fftFrame = gui.QFrame(self)
        fftFrame.setFrameShape(gui.QFrame.StyledPanel)
        self.FFTGraph …
Run Code Online (Sandbox Code Playgroud)

matplotlib pyside python-3.x

3
推荐指数
1
解决办法
2818
查看次数

如何解析可能具有多行值的制表符分隔文件?

我有一个文件,用不同的数据点分隔:

"ID"    "Value"
"1" "This is a value"
Run Code Online (Sandbox Code Playgroud)

我可以通过简单地使用内置的str函数轻松地从中提取数据split.但有时候我遇到这个问题:

"ID"    "Value"
"1" "This is a value"
"2" "This is another
value"
"3" "Just one more"
Run Code Online (Sandbox Code Playgroud)

第二个值跨越多行的位置.如何捕获每个数据点的完整性?

最终我想要的是一个字典列表,如下所示:

[{'ID':'1', 'Value':'This is a value'}, {'ID':'2', 'Value':'This is another\nvalue'}, {'ID':'3', 'Value':'Just one more'}]
Run Code Online (Sandbox Code Playgroud)

python parsing multiline

3
推荐指数
1
解决办法
510
查看次数