写入.oct文件中的矩阵而不循环? [英] Write to a matrix in .oct file without looping?

查看:150
本文介绍了写入.oct文件中的矩阵而不循环?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Octave .oct文件中,可以提取一个子矩阵:

  B = A.extract 1,c-1,b-1,d-1); 

等效于B = A(a:b,c:d)可以以类似的方式写入矩阵的子集,

  A(a-1,c-1,b -1,d-1)= B; //一些其他更小的矩阵

或者我必须循环相关的行/ c> c> c> $ <$> c> Array ,您可以使用以下方法之一(请参阅文档):

  Array< T& & insert(const Array& a,octave_idx_type r,octave_idx_type c)
Array< T> & insert(const Array< T& a,const Array< octave_idx_type>& idx)

只需要知道左上角的下标索引(或其对应的N维)。下面将把二维矩阵 B 插入到二维矩阵 A 中,在坐标 ,c)

  A.insert(B,a,c) 

对于更多维度,您需要创建一个 Array< octave_idx_type> 以该点的坐标表示。


In an Octave .oct file it is possible to extract a submatrix thus:

B = A.extract(a-1,c-1,b-1,d-1) ;

the equivalent of B = A(a:b,c:d) in Octave code, but is it possible to write to a subset of a matrix in a similar manner,

A(a-1,c-1,b-1,d-1) = B ; // some other smaller matrix 

or would I have to loop over the relevant rows/columns and write element by element?

解决方案

Assuming A is of class Array, you can use one of the following methods (see the documentation):

Array<T> & insert (const Array<T> &a, octave_idx_type r, octave_idx_type c)
Array<T> & insert (const Array<T> &a, const Array<octave_idx_type> &idx)

You only need to know the subscript index for the top left corner (or its equivalent for N dimensions). The following will insert the 2D matrix B into the 2D matrix A, at coordinates (a, c)

A.insert (B, a, c);

For more dimensions, you'll need to create an Array<octave_idx_type> with coordinates for that point.

这篇关于写入.oct文件中的矩阵而不循环?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆