help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

negative indexing of matrix or general access


From: Zbigniew Komarnicki
Subject: negative indexing of matrix or general access
Date: Tue, 7 Oct 2008 22:33:34 +0200
User-agent: KMail/1.9.9

Hello,

is possible to write a class in OCT file by which I will can make the 
following access by negative index to a matrix or general access for 
arbitrary index . For example


% this will be create a matrix with zero values (for example by calling a 
% constructor in C++ code in OCT file)
% or
% inserting zero values to such matrix (by operator=)
A(-3:3, 2:5) = 0  

I can do it in Fortran 95, but i think it is also possible in octave by 
writing some function or classes to deal with such indexing, by simple adding 
offset internally. For example, 

this 
A(-3:3, 2:5) = 0

internally can be written in C++ as

...
{
// if we set:
//     int min_idx_1=-3, min_idx_2=2; 
//     int max_idx_1=3, max_idx_2=5;

  //scaling to 0, because the array start in C++ from 0
  int offset_min_idx_1 = - min_idx_1;  
  int offset_min_idx_2 = - min_idx_2;

  for (int i=0; i<max_idx_1; ++i)
    for (int j=0; j<max_idx_2; ++j)
       A(i+offset_min_idx_1, j+offset_min_idx_2) = 0;
    end
  end

}
...


I have no idea how to start write such code to do it in OCT file, but i think 
it is possible. Then it can be used in octave very natural as in Fortran 
without making this scaling (in octave to 1, because octave start matrices 
from 1 index; in C++ to 0 index), because now i must to do it by scaling to 1 
in octave, for example in this way


% my goal:  A(-3:3, 2:5) = 0

% but now I doing it for example in this way
A(1:7, 1:4) = 0          


Could someone  point me how to start write such code in OCT file or maybe 
someone write such code and will be share such code  to octave?

Exactly how to write a simple class in C++ by OCT files in octave and simple 
use it in octave? Could someone show it step by step how to do it? Especially 
how is invoked constructor and operator= for an example  class in C++ by OCT 
file.

Thank you for your time.

Thank you and sorry for my English language.

Best wishes,
Zbigniew


reply via email to

[Prev in Thread] Current Thread [Next in Thread]