1

Where did I go wrong? the problem is in: R = sqrt(bsxfun(@minus,XX,(XX)').^2+bsxfun(@minus,YY,(YY)').^2);

EO = 8.8541e-12; %eps0
A2 = 1.0e-2; %2a
N = 100; %num of subareas in a plate
M = sqrt(N); %num of subareas in one axis
DX = A2/M; % 2b
DY = DX; %2b
DL = DX; %2b

%  SECOND, CALCULATE THE ELEMENS OF THE COEFFICIENT MATRIX A
% Write all the subareas centers coordinates to X and Y 
%  SECOND, CALCULATE THE ELEMENS OF THE COEFFICIENT MATRIX A
% Write all the subareas centers coordinates to X and Y 
x = linspace(DL*0.5,DL*(M-0.5),M);
y = x;
[XX,YY]=meshgrid(x,y);
%%L = NaN(N,N);
**R = sqrt(bsxfun(@minus,XX,(XX)').^2+bsxfun(@minus,YY,(YY)').^2);**
idx_diagL = find(eye(N)~=0);
idx_not_diagL = find(eye(N)==0);
L(idx_not_diagL) = DL^2./(4.*pi*EO*R(mod(idx_not_diagL,10),floor(idx_not_diagL/N)));
L(idx_diagL)  = DL*0.8814/(pi*EO); %ln(1+sqrt(2)= 0.8814
Shai
  • 111,146
  • 38
  • 238
  • 371
Idan Banani
  • 131
  • 2
  • 13
  • Also see [this question](http://stackoverflow.com/questions/20054047/subscript-indices-must-either-be-real-positive-integers-or-logicals-generic-sol) for [the generic solution to this problem](http://stackoverflow.com/a/20054048/983722). – Dennis Jaheruddin Nov 27 '13 at 15:40

1 Answers1

4

The problem is not where you say it is, but in the following line:

L(idx_not_diagL) = DL^2./(4.*pi*EO*R(mod(idx_not_diagL,10),floor(idx_not_diagL/N)));

In short, your problem is that you specify zero indices for matrix R, but in MATLAB zero indices are illegal (they start from 1, not 0!).

Now, where do you get zero indices? You index into R(..., ...) by using the following row and column subscripts:

mod(idx_not_diagL, 10)

and

floor(idx_not_diagL / N))

which both get zero values occasionally.

As a fix, I recommend using the following for the row indices:

mod(idx_not_diagL, 10) + 1

As for the column indices, there is another problem. The floor(...) expression ranges from 0 to 99. Once you fix it (I'm not sure what you're trying to achieve), it will work.

Eitan T
  • 32,660
  • 14
  • 72
  • 109
  • Thanks but I think what I've tried to do is like impossible mission... I tried to make R the NXN Distance Matrix but failed.... Ofcourse what I did here is R(10,10) instead and tried to figure out the right indices while accessing R ,pretty hardcore... – Idan Banani Dec 09 '12 at 18:21
  • I'm not sure that I understand what you've just said. – Eitan T Dec 10 '12 at 00:24