首页 \ 问答 \ 使用matlab中的逐元加法将值添加到矩阵的对角线(adding values to diagonals of matrix using element-wise addition in matlab)

使用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:

Adding sums to diagonals

Thanks!


原文:https://stackoverflow.com/questions/29000277
更新时间:2023-06-11 11:06

最满意答案

您可以使用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 ...
  • 我不明白你为什么不喜欢迭代。 这对我来说似乎是一个很好的解决方案。 我将借此机会构建一个可重用的递归控制迭代器。 但是,如果您不想这样做,那么您可以尝试使用当前解决方案的简单变体。 在使窗体可见之前,请设置其位置,使其不显示在任何监视器上。 然后,当你再次隐藏时,恢复正确的位置。 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 ...
  • 您的计算机随附的Perfmon可以执行此操作。 您还可以在任务管理器进程选项卡(“处理计数”)中添加一列。 Perfmon说明 添加一个计数器(点击+) 选择Performance对象下的Process 在计数器列表中选择处理计数 从实例列表中选择您的过程 点击添加,点击关闭 要获得范围图,您必须在列表中右键单击它,选择属性,然后选择正确的比例(.1或.01可能是正确的) 编辑(响应添加的信息):我认为您刚刚证明创建RichTextBox不会导致Handles被分配。 我不认为它真的需要一个,直到你编辑控件 ...
  • 您的问题的解决方案确实似乎是使用卷的句柄调用FlushFileBuffers() 。 在页面底部附近MSDN有这样的说法: 要刷新卷上的所有打开文件,请使用卷的句柄调用FlushFileBuffers。 调用者必须具有管理权限...... 该页面上的其他信息让我相信这也会刷新元数据,尽管在这个特定情况下并没有直接说明。 也许你可以告诉我这个。 为了退出细节并暂时看一下大图,由于各种原因,必须有一个适用于此的API,尽管我认为它可能不公开。 I think I've got it. To reiterate ...
  • 你可能已达到极限。 请注意,平台(macOS,Linux,Windows)之间的手柄数量差异很大,因此如果您计划在不同平台上运行此手柄,则需要对所有平台进行测试。 如果您使用的是从Resource ( Color , Font , Image , Cursor ,....)派生的SWT类,则必须在完成后调用对象上的dispose 。 如果不这样做会泄漏手柄。 您还应尝试共享这些资源 - 例如,不要每次都创建新的Color 。 使用处理共享颜色的管理器类,管理器类也可以处理资源的处理。 JFace提供了Col ...
  • 从效率的角度来看,似乎使用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 ...
  • 您可以使用EnumChildWindows来枚举第三方应用程序窗口的所有子窗口,并测试每个枚举窗口的类名,以查看它是否为“文本框”类。 例: function EnumChildren(hwnd: HWND; lParam: LPARAM): BOOL; stdcall; const TextBoxClass = 'EDIT'; (?) var ClassName: array[0..259] of Char; begin Result := True; GetClassName(hwnd, ...
  • 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都是指针类型,所以你可以自由地和无损地在它们之间 ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。