Array indices must be positive integers or logical values.
    5 views (last 30 days)
  
       Show older comments
    
Here I am having the most asked question on Matwork Forums and still unable to solve my problem.
The code I have is listed below, but since I am a newbie. I should describe what I am trying to achieve here;
with line 59-66 i tried to pull out the variables from table,
than with the for command i am planning to use these variables in line 59 to 66 in a basic formulations such as multiplication so on. 
I achieved the same procedure in the first " For " loop but I don't know what I am doing wrong now.
( Sorry for the Turkish explanations with green texts)
echo off all
clc
nodeX = [0,5,9.17,12,0,5,9.17,12,0,5,8,9.17,12]; % noktalarin x koordinatlari
nodeY = [8,8,8,8,4,4,5.5,5.5,0,0,0,2.83,4]; % noktalarin y koordinatlari
elemX = [5,6,6,7,7,7,5,9,10,11,6,7,7]; % i icin olusan ucgenlerin global nokta karsiliklari
elemY = [1,1,2,2,3,4,6,6,6,6,7,12,8]; % j icin
elemZ = [6,2,7,3,4,8,9,10,11,12,12,13,13]; % k icin
varTable = [];
fprintf("e xi\txj\txk\tyi\tyj\tyk\tck\tci\tcj\tbi\tbj\tbk\tA\n"); % tablo basligini formatla
for i = 1:length(elemX)
    % sirasiyla elemanlari okutuyoruz 
    currElemX = elemX(i);
    currElemY = elemY(i);
    currElemZ = elemZ(i);
    % i ye karsilik gelen global noktalarin koordinat karsiliklari
    % bulunuyor
    xi = nodeX(elemX(i));
    xj = nodeX(elemY(i));
    xk = nodeX(elemZ(i));
    yi = nodeY(elemX(i));
    yj = nodeY(elemY(i));
    yk = nodeY(elemZ(i));
    % gerekli hesaplama yapiliyor
    ck = xj - xi;
    ci = xk - xj;
    cj = xi - xk;
    bi = yj - yk;
    bj = yk - yi;
    bk = yi - yj;
    % alan hesabi
    A = abs(0.5 * (xi * yj + xj * yk + xk * yi - xi * yk - xj * yi - xk * yj));
    %dongunun disinda kullanmak icin bulunan degerleri sakla
    varTable = [varTable ; ck,ci,cj,bi,bj,bk,A];
    % ekrana uygun formatla yazdiriliyor
    fprintf("%d %.2f\t%.2f\t%.2f\t%.2f\t%.2f\t%.2f\t%.2f\t%.2f\t%.2f\t%.2f\t%.2f\t%.2f\t%.4f\t\n",i,xi,xj,xk,yi,yj,yk,ck,ci,cj,bi,bj,bk,A);
end
Kcal= array2table(varTable, 'Variablenames',{'ck','ci','cj','bi','bj','bk','A'}) %K 3x3 matris hesabi icin tablo
%tablodaki degerleri disari cekiyorum sutunlari ayri olarak
%A='Tablename'.'variablename' komutu ile
%n sembolu sondaki sadece karisiklik onlemek amacli
cin=Kcal.ci;
cjn=Kcal.cj;
ckn=Kcal.ck;
bin=Kcal.bi;
bjn=Kcal.bj;
bkn=Kcal.bk;
An=Kcal.A;
for i=1:height(Kcal)
    currcin=cin(i);
    currcjn=cjn(i);
    currckn=ckn(i);
    currbin=bin(i);
    currbjn=bjn(i);
    currbkn=bkn(i);
    currAn=An(i);
    bin=bin(bin(i));
    bjn=bjn(bjn(i));
    K11= bin-bjn
end
1 Comment
  Adam
      
      
 on 24 Oct 2019
				Simplest thing to do is use the debugger.  At a guess, not all values in bin or bjn are positive.  If you use the 'Pause on errors' option in the Run menu then it will stop at the right point in the code.
Accepted Answer
More Answers (0)
See Also
Categories
				Find more on Matrix Indexing in Help Center and File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!