MATLAB Answers

Array indices must be positive integers or logical values.

6 views (last 30 days)
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
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);
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;
for i=1:height(Kcal)
K11= bin-bjn

  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.

Sign in to comment.

Accepted Answer

Anilcan Taner
Anilcan Taner on 28 Oct 2019
Problem is solved with the code that I've commented to Star Strider.
Matlab is so far has the very helpful community thanks for all the efford


Sign in to comment.

More Answers (0)


Translated by