使用matlab中的逐元加法将值添加到矩阵的对角线(adding values to diagonals of matrix using element-wise addition in matlab)
我正在编写一个在矩阵上运行的脚本,我遇到了需要将前一个矩阵的对角线总和与新矩阵的对角线元素相加的问题。 到目前为止,我对这个特定函数的代码(下面将更详细地描述)是:
t = 1; for k = (m-1):-1:-(m-1) C = bsxfun(@plus, diag(B, k), d); g(t) = sum(diag(B, k)); t = t + 1; end
其中d是1x3阵列,C应该是3x3阵列; 然而,C被输出为1×3的阵列,使得第一个对角线被求和并加到d,然后主对角线被求和并加到d,并且最后的对角线被求和并加到d上。
有没有一种方法可以使C的值为:第一个对角线是它加入到d的最后一个元素的个别元素,d的中间元素的主对角线的各个元素以及底部对角线的元素添加到d的第一个元素? (虽然仍然适用于任何阵列大小?)
这张图片描述了我想要达到的目标:
谢谢!
I am writing a script that operates on matrices, and I have run into the problem of needing to add the sum of the diagonals of a previous matrix to the diagonal elements of a new matrix. The code I have so far for this particular function (described in more detail below) is:
t = 1; for k = (m-1):-1:-(m-1) C = bsxfun(@plus, diag(B, k), d); g(t) = sum(diag(B, k)); t = t + 1; end
where d is a 1x3 array, and C is supposed to be a 3x3 array; however, C is being output as a 1x3 array in such a way that the first diagonal is being summed and added to d, then the main diagonal is being summed and added to d, and the final diagonal is being summed and added to d.
Is there a way I can get the values of C to be such that the first diagonal is the sum of it's individual elements added to the last element of d, the main diagonal's individual elements added to the middle element of d, and the bottom diagonal's elements added to the first element of d? (while still working for any array size?)
Here is a picture that describes what I'm trying to achieve:
Thanks!
原文:https://stackoverflow.com/questions/29000277
最满意答案
您可以使用
EnumChildWindows
来枚举第三方应用程序窗口的所有子窗口,并测试每个枚举窗口的类名,以查看它是否为“文本框”类。 例:function EnumChildren(hwnd: HWND; lParam: LPARAM): BOOL; stdcall; const TextBoxClass = 'EDIT'; (?) var ClassName: array[0..259] of Char; begin Result := True; GetClassName(hwnd, ClassName, Length(ClassName)); if ClassName = TextBoxClass then TStrings(lParam).Add(IntToHex(hwnd, 8)); end; procedure TForm1.Button1Click(Sender: TObject); begin Memo1.Clear; EnumChildWindows(OtherAppWnd, @EnumChildren, UINT_PTR(Memo1.Lines)); end;
You can use
EnumChildWindows
to enumerate all child windows of the third party application's window and test the class name of each enumerated window to see if it is the "Text Box" class. Example:function EnumChildren(hwnd: HWND; lParam: LPARAM): BOOL; stdcall; const TextBoxClass = 'EDIT'; (?) var ClassName: array[0..259] of Char; begin Result := True; GetClassName(hwnd, ClassName, Length(ClassName)); if ClassName = TextBoxClass then TStrings(lParam).Add(IntToHex(hwnd, 8)); end; procedure TForm1.Button1Click(Sender: TObject); begin Memo1.Clear; EnumChildWindows(OtherAppWnd, @EnumChildren, UINT_PTR(Memo1.Lines)); end;
相关问答
更多-
DataGridViewForm的控件不是静态的,您需要将DataGridViewForm的实例传递给DataGridViewForm的实例,然后DataGridViewClass将可以访问DataGridViewForm所有控件,这是一个基本示例: Public Class DataGridViewForm Private DgvClassObj As DataGridViewClass Sub New() ' pass this DataGridViewForm ins ...
-
为窗体和子控件初始化窗口句柄而不显示(Initialize window handle for form and child controls without displaying)[2023-05-09]
我不明白你为什么不喜欢迭代。 这对我来说似乎是一个很好的解决方案。 我将借此机会构建一个可重用的递归控制迭代器。 但是,如果您不想这样做,那么您可以尝试使用当前解决方案的简单变体。 在使窗体可见之前,请设置其位置,使其不显示在任何监视器上。 然后,当你再次隐藏时,恢复正确的位置。 I don't understand why you don't like iterating. It seems like a good solution to me. I'd take the opportunity to b ... -
如何确定应用程序正在使用的窗口句柄数?(How do I determine number of window handles an application is using?)[2022-05-13]
您的计算机随附的Perfmon可以执行此操作。 您还可以在任务管理器进程选项卡(“处理计数”)中添加一列。 Perfmon说明 添加一个计数器(点击+) 选择Performance对象下的Process 在计数器列表中选择处理计数 从实例列表中选择您的过程 点击添加,点击关闭 要获得范围图,您必须在列表中右键单击它,选择属性,然后选择正确的比例(.1或.01可能是正确的) 编辑(响应添加的信息):我认为您刚刚证明创建RichTextBox不会导致Handles被分配。 我不认为它真的需要一个,直到你编辑控件 ... -
您的问题的解决方案确实似乎是使用卷的句柄调用FlushFileBuffers() 。 在页面底部附近MSDN有这样的说法: 要刷新卷上的所有打开文件,请使用卷的句柄调用FlushFileBuffers。 调用者必须具有管理权限...... 该页面上的其他信息让我相信这也会刷新元数据,尽管在这个特定情况下并没有直接说明。 也许你可以告诉我这个。 为了退出细节并暂时看一下大图,由于各种原因,必须有一个适用于此的API,尽管我认为它可能不公开。 I think I've got it. To reiterate ...
-
SWT:没有更多控制句柄(SWT: No more Control handles)[2022-02-03]
你可能已达到极限。 请注意,平台(macOS,Linux,Windows)之间的手柄数量差异很大,因此如果您计划在不同平台上运行此手柄,则需要对所有平台进行测试。 如果您使用的是从Resource ( Color , Font , Image , Cursor ,....)派生的SWT类,则必须在完成后调用对象上的dispose 。 如果不这样做会泄漏手柄。 您还应尝试共享这些资源 - 例如,不要每次都创建新的Color 。 使用处理共享颜色的管理器类,管理器类也可以处理资源的处理。 JFace提供了Col ... -
@Register还是
?(@Register or ?)[2023-02-14] 从效率的角度来看,似乎使用web.config中的controls元素会更好,因为它在应用程序启动时会缓存一次; 而每页请求都会处理页面指令Register 。 From an efficiency standpoint, it would seem that using the controls element in web.config would be better, because it is cached once when the application starts; whereas the ... -
嗯,通常你不应该得到句柄的秘密; 它们通常只是指向您正在使用的lib / API内部的一些内部结构的指针,只有lib才知道如何使用它。 没有关于句柄的通用规则或任何内容,您必须按照lib的文档所示使用它们。 Well, usually you are not supposed to get the secrets of handles; they are usually just a pointer to some internal structure inside the lib/API you are ...
-
如何获得具有相同类名的不同控件的句柄?(How to get handles of different controls with the same class name ?)[2021-12-26]
您可以使用EnumChildWindows来枚举第三方应用程序窗口的所有子窗口,并测试每个枚举窗口的类名,以查看它是否为“文本框”类。 例: function EnumChildren(hwnd: HWND; lParam: LPARAM): BOOL; stdcall; const TextBoxClass = 'EDIT'; (?) var ClassName: array[0..259] of Char; begin Result := True; GetClassName(hwnd, ... -
GUI句柄在哪里管理?(Where are GUI handles managed?)[2024-03-03]
win32k.sys负责处理USER和GDI请求。 win32k驱动程序是图形堆栈中导出600多个函数的关键组件。 它使用另一个名为_W32pServiceTable的表扩展了系统服务描述符表(SSDT) 。 这个驱动程序没有主内核模块(ntoskrnl.exe)那么大,但它与用户模式的交互同样重要。 win32k的服务表包含少于300个功能,具体取决于Windows的版本。 win32k驱动程序通常使用用户模式回调系统将控制权转移到用户模式。 用户模式模块和内核模式驱动程序之间的接口已经构建,以便于窗口创 ... -
HWND和X11窗口句柄都是指针类型。 你可以利用这个优势。 做这样的事情: struct WindowHandleImpl; typedef WindowHandleImpl *WindowHandle; C ++允许您使用指向不完整类型的指针 - 只是不要在任何地方定义WindowHandleImpl的内容, WindowHandle是完全不透明的类型,可以由App传递而不公开任何实现细节。 因为HWND ,X11 Window和WindowHandle都是指针类型,所以你可以自由地和无损地在它们之间 ...