Pinescript Array saying index is out of bounds when I am checking the size first? - pine-script-v5

Pinescript array, checking to see if array size is minimal needed, yet it is display this error enter image description here
Here is the code I am refering:
if confirmedTriangle and array.size(triangle_price)>4 and array.size(triangle_index)>4
for i = 0 to 3
//Slope
xIndexDis = array.get(triangle_index, 0) - array.get(triangle_index, 4)// : na
yPriceDis = array.get(triangle_price, 0) - array.get(triangle_price, 4)// : na
xIndexDis2 = array.get(triangle_index, 3) - array.get(triangle_index, 1)// : na
yPriceDis2 = array.get(triangle_price, 3) - array.get(triangle_price, 1)// : na
m = yPriceDis / xIndexDis //Gradient for bottom line
m2 = yPriceDis2 / xIndexDis2 // Gradient for top line
x1 = array.get(triangle_index, i)-testLength
y1 = array.get(triangle_price, i)
x2 = array.get(triangle_index, i+1)-testLength
y2 = array.get(triangle_price, i+1)
array.push(tri_array, line.new(x1,y1,x2,y2, color=color.white))
xa1 = array.get(triangle_index,4)
xa2 = array.get(triangle_index,0)
xb1 = array.get(triangle_index,3)
xb2 = array.get(triangle_index,1)
ya1 = array.get(triangle_price,4)
ya2 = array.get(triangle_price,0)
yb1 = array.get(triangle_price,3)
yb2 = array.get(triangle_price,1)
label.new(bar_index, high+atr, text="Xa1 = " + str.tostring(xa1) + " / Ya1 = " + str.tostring(ya1) + "\n Xa2 = " + str.tostring(xa2) + " / Ya2 = " + str.tostring(ya2) + "\nXb1 = " + str.tostring(xb1) + " / Yb1 = " + str.tostring(yb1) + "\n Xb2 = " + str.tostring(xb2) + " / Yb2 = " + str.tostring(yb2))
I don't get any errors on sometimeframes but the majority do present the same error,

Found the issues,
I assigned array.size(triangle_price) to a variable
e.g. arraySize = array.size(triangle_price)
In confirmedTriangle I was checking if arraySize>4, but the array size had been changed since that check
Simple fix was just to remove "arraySize = array.size(triangle_price)" and use array.size(triangle_price) in each check

Related

Pillow new RGB screen not generating

I built a test program using import PIL.imagedraw etc etc and was able to use the draw.line command to draw various lines. All good. In a new program I added new code which built a matrix list of x/y/z points (and cosine/sine expressions with math.lib), an input command for some variables, and then the draw.line command as in the previous code, but now the RGB window is not showing at all. The program doesn’t end and gives no errors. (Pythonista on iOS iPad Pro)
The test program, a noob attempt at perspective projection (which works as expected):
import PIL.ImageDraw as ImageDraw,PIL.Image as Image, PIL.ImageShow as ImageShow
im = Image.new("RGB", (1200,800))
draw = ImageDraw.Draw(im)
GL_z = 0
PP_y = 0
SP_x = 300
SP_y = -400
SP_z = 600
org=600
answer=0
width=100
depth=500
height=500
SP_z1=SP_z+height
px_1 = org
py_1 = org
px_2 = org+90
py_2 = 50 + org
px_3 = -160 + org
py_3 = 550 + org
px_4 = -250 + org
py_4 = 500+org
while answer==0:
SP_z1=SP_z-height
px1_1 = ((px_1 - SP_x)/(py_1 - SP_y))*(py_1 - PP_y)
px1_2 = ((px_2 - SP_x)/(py_2 - SP_y))*(py_2 - PP_y)
px1_3 = ((px_3 - SP_x)/(py_3 - SP_y))*(py_3 - PP_y)
px1_4 = ((px_4 - SP_x)/(py_4 - SP_y))*(py_4 - PP_y)
py1_1 = ((SP_z-GL_z)/(py_1-SP_y))*(py_1-PP_y)
py1_2 = ((SP_z-GL_z)/(py_2-SP_y))*(py_2-PP_y)
py1_3 = ((SP_z-GL_z)/(py_3-SP_y))*(py_3-PP_y)
py1_4 = ((SP_z-GL_z)/(py_4-SP_y))*(py_4-PP_y)
py1_5 = ((SP_z1-GL_z)/(py_1-SP_y))*(py_1-PP_y)
py1_6 = ((SP_z1-GL_z)/(py_2-SP_y))*(py_2-PP_y)
py1_7 = ((SP_z1-GL_z)/(py_3-SP_y))*(py_3-PP_y)
py1_8 = ((SP_z1-GL_z)/(py_4-SP_y))*(py_4-PP_y)
px1_1old = px1_1
px1_2old = px1_2
px1_3old = px1_3
px1_4old = px1_4
py1_1old = py1_1
py1_2old = py1_2
py1_3old = py1_3
py1_4old = py1_4
py1_5old = py1_5
py1_6old = py1_6
py1_7old = py1_7
py1_8old = py1_8
SP_yold = SP_y
draw.line((0,SP_y,1200,SP_y),fill=(255,255,255))
draw.line((px1_1,py1_1,px1_2,py1_2),fill=(0,0,255))
draw.line((px1_2,py1_2,px1_3,py1_3),fill=(0,255,0))
draw.line((px1_3,py1_3,px1_4,py1_4),fill=(255,255,255))
draw.line((px1_4,py1_4,px1_1,py1_1),fill=(100,255,0))
draw.line((px1_1,py1_1,px1_1,py1_5),fill=(255,255,255))
draw.line((px1_1,py1_5,px1_2,py1_6),fill=(255,255,255))
draw.line((px1_2,py1_6,px1_3,py1_7),fill=(255,255,255))
draw.line((px1_3,py1_7,px1_4,py1_8),fill=(255,255,255))
draw.line((px1_4,py1_8,px1_4,py1_4),fill=(150,150,0))
#draw.line((px1_1,py1_1,px1_2,py1_2),fill=(255,255,255))
#draw.line((px1_2,py1_2,px1_3,py1_3),fill=(255,255,255))
#draw.line((px1_3,py1_3,px1_4,py1_4),fill=(255,255,255))
#draw.line((px1_4,py1_4,px1_1,py1_1),fill=(255,255,255))
im.show()
move = input("''")
if move == "w":
SP_y += 50
if move == "s":
SP_x -= 50
if move == "z":
SP_y -= 50
if move == "a":
SP_x += 50
if move == "-":
SP_z -= 50
if move == "=":
SP_z += 50
draw.line((0,SP_yold,1200,SP_yold),fill=(0,0,0))
draw.line((px1_1old,py1_1old,px1_2old,py1_2old),fill=(0,0,0))
draw.line((px1_2old,py1_2old,px1_3old,py1_3old),fill=(0,0,0))
draw.line((px1_3old,py1_3old,px1_4old,py1_4old),fill=(0,0,0))
draw.line((px1_4old,py1_4old,px1_1old,py1_1old),fill=(0,0,0))
draw.line((px1_1old,py1_1old,px1_1old,py1_5old),fill=(0,0,0))
draw.line((px1_1old,py1_5old,px1_2old,py1_6old),fill=(0,0,0))
draw.line((px1_2old,py1_6old,px1_3old,py1_7old),fill=(0,0,0))
draw.line((px1_3old,py1_7old,px1_4old,py1_8old),fill=(0,0,0))
draw.line((px1_4old,py1_8old,px1_4old,py1_4old),fill=(0,0,0))
And this is the code that refuses to draw anything:
import math
import decimal
decimal.getcontext().prec = 6
import PIL.ImageDraw as ImageDraw,PIL.Image as Image, PIL.ImageShow as ImageShow
im = Image.new("RGB", (1200,800))
draw = ImageDraw.Draw(im)
PP_y = 0
SP_x = 300
SP_y = -400
SP_z = 600
org=600
answer=0
dims=[]
for i in range (1, 5):
dim = int(input())
dims.append(dim)
dims[3] = (dims[3]*math.pi)/180
obj1 = [[1,2,3],[4,5,6],[7,8,9],[10,11,12],[13,14,15],[16,17,18],[19,20,21],[22,23,24]]
y1 = [0,0,0,0,0,0,0,0]
y2 = [0,0,0,0,0,0,0,0]
y3 = [0,0,0,0,0,0,0,0]
x1 = [0,0,0,0,0,0,0,0]
z1 = [0,0,0,0,0,0,0,0]
ymod = [0,0,0,0,0,0,0,0]
xmod = [0,0,0,0,0,0,0,0]
obj1[0]=[0,0,0]
obj1[1]=[dims[0] * math.cos(dims[3]),dims[0] * math.sin(dims[3]),0]
obj1[2]=[obj1[1][0] - (dims[1] * math.sin(dims[3])),obj1[1][1] + (dims[1] * math.cos(dims[3])),0]
obj1[3]=[dims[1] * math.sin(dims[3]),dims[1] * math.cos(dims[3]),0]
obj1[4]=[0,0,dims[2]]
obj1[5]=[dims[0] * math.cos(dims[3]),dims[0] * math.sin(dims[3]),dims[2]]
obj1[6]=[obj1[1][0] - (dims[1] * math.sin(dims[3])),obj1[1][1] + (dims[1] * math.cos(dims[3])),dims[2]]
obj1[7]=[dims[1] * math.sin(dims[3]),dims[1] * math.cos(dims[3]),dims[2]]
for i in range (0,7):
y1[i]=obj1[i][1]-PP_y
y2[i]=obj1[i][1]-SP_y
y3[i]=y1[i]/y2[i]
x1[i]=obj1[i][0]-SP_y
z1[i]=obj1[i][2]-SP_z
obj1[i][0]=obj1[i][0] - (x1[i] * y3[i])
obj1[i][2]=obj1[i][2] - (z1[i] * y3[i])
#print(dims)
#print(obj1)
#print(y1,y2,y3,x1,z1,xmod,ymod)
while (True):
draw.line((obj1[0][0],obj1[0][2],obj1[1][0],obj1[1][2]),fill=(255,255,255))
Ah found the error, left out im.show(). Pretty fundamental…
reference
https://pillow.readthedocs.io/en/stable/reference/Image.html

MATLAB taking hours to solve an equation

I've been trying to solve an equation composed of matrices. MATLAB has run it for almost two hours now and nothing. It's supposed to multiply some 8x8 matrices and invert one 8x8 matrix. Should it take this long? I'm using an I7 8th gen 2.20 running at 4ghz, 16 gb and RTX 2060.
Code (the final line is where MATLAB is taking so long):
%% Modelagem do conversor SEPIC-Zeta em espaço de estados
%% Declarando variáveis simbólicas:
% Variáveis com o índice "_" são derivadas de primeira ordem.
% RL1, RL2, RL3 e RL4 são as resistências série dos indutores.
% RseC1, RseC2, RseC3 e RseC4 são as resistências série dos capacitores.
Vi = sym('Vi');
C1 = sym('C1');
C2 = sym('C2');
C3 = sym('C3');
C4 = sym('C4');
L1 = sym('L1');
L2 = sym('L2');
L3 = sym('L3');
L4 = sym('L4');
VC1 = sym('VC1');
VC2 = sym('VC2');
VC3 = sym('VC3');
VC4 = sym('VC4');
VC1_ = sym('VC1_');
VC2_ = sym('VC2_');
VC3_ = sym('VC3_');
VC4_ = sym('VC4_');
IL1 = sym('IL1');
IL2 = sym('IL2');
IL3 = sym('IL3');
IL4 = sym('IL4');
IL1_ = sym('IL1_');
IL2_ = sym('IL2_');
IL3_ = sym('IL3_');
IL4_ = sym('IL4_');
RL1 = sym('RL1');
RL2 = sym('RL2');
RL3 = sym('RL3');
RL4 = sym('RL4');
RseC1 = sym('RseC1');
RseC2 = sym('RseC2');
RseC3 = sym('RseC3');
RseC4 = sym('RseC4');
Ro = sym('Ro');
D = sym('D');
s = sym('s');
%% Determinando as matrizes de coeficientes do conversor em t = [0, DTs]:
% Equações LKT no conversor:
eqn11 = IL1_ - (-RL1*IL1 + Vi)/L1 == 0;
eqn21 = IL2_ - ((RseC1 - RL2)*IL2 - VC1)/L2 == 0;
eqn31 = IL3_ - (VC2 + (RseC2 - RL3)*IL3 + RseC2*IL4)/L3 == 0;
eqn41 = IL4_ - ((-VC3 + RseC2*C2*VC2_ - (RseC3 + RL4)*IL4 + Ro*C4*VC4_ + VC2)/L4) == 0;
eqn51 = VC1_ - (Vi - RL1*IL1 + L1*IL1_ + VC1 - L2*IL2_)/C1*(RseC1 - RL2) == 0;
eqn61 = VC2_ - (-RseC1*IL2 - VC1 - RL2*IL2 - L2*IL2_ + VC2 + L3*IL3_ + RL3*IL3)/(C2*RseC2) == 0;
eqn71 = VC3_ - (Ro*IL4 - Ro*C4*VC4_ - VC3 - L4*IL4_ + L3*IL3_ + RL3*IL3 - RL4*IL4)/(C3*RseC3) == 0;
eqn81 = VC4_ - (Ro*IL4 - VC4)/(C4*(RseC4 + Ro)) == 0;
% Solucionando o sistema de equações lineares:
sol1 = solve([eqn11, eqn21, eqn31, eqn41, eqn51, eqn61, eqn71, eqn81], [IL1_, IL2_, IL3_, IL4_, VC1_, VC2_, VC3_, VC4_]);
% Separando as matrizes A e B dos coeficientes:
system_A1 = [sol1.IL1_ == IL1_, sol1.IL2_ == IL2_, sol1.IL3_ == IL3_, sol1.IL4_ == IL4_,...
sol1.VC1_ == VC1_, sol1.VC2_ == VC2_, sol1.VC3_ == VC3_, sol1.VC4_ == VC4_];
vars1 = [ IL1, IL2, IL3, IL4, VC1, VC2, VC3, VC4 ];
vars21 = [ Vi ];
% Definindo as matrizes A1, B1, C1 e D1:
A1 = equationsToMatrix(system_A1,vars1);
B1 = equationsToMatrix(system_A1,vars21);
C1_ = [ 0; 0; 0; RseC4*Ro/(RseC4 + Ro); 0; 0; 0; Ro/(RseC4 + Ro) ];
D1 = 0;
%% Deterninando as matrizes dos coeficientes em t = [DTs, Ts]:
eqn12 = IL1_ - (-Vi + IL1*(RseC1 - RL1) + VC1 + RL2*IL2 + L2*IL2_)/L1 == 0;
eqn22 = IL2_ - (RseC2*IL1 + IL2*(-RL2 + RseC2) + VC2)/L2 == 0;
eqn32 = IL3_ - (-VC3 -RL3*IL3 - RseC3*IL3)/L3 == 0;
eqn42 = IL4_ - ((IL4*RL4 - Ro*IL4 - Ro*C4*VC4_)/L4) == 0;
eqn52 = VC1_ - (Vi - RseC1*IL1 - L1*IL1_ - VC1 + RL2*IL2 + L2*IL2_)/C1*(RseC1 + RseC2 - RL1) == 0;
eqn62 = VC2_ - (RL2*IL2 + L2*IL2_ - VC2)/(C2*RseC2) == 0;
eqn72 = VC3_ - (-Ro*IL4 - Ro*C4*VC4_ - VC3 + L4*IL4_ - L3*IL3_ + RL4*IL4)/(C3*(RL3 + RseC3)) == 0;
eqn82 = VC4_ - (Ro*IL4 - VC4)/(C4*(RseC4 - Ro)) == 0;
% Solucionando o sistema de equações lineares:
sol2 = solve([eqn12, eqn22, eqn32, eqn42, eqn52, eqn62, eqn72, eqn82], [IL1_, IL2_, IL3_, IL4_, VC1_, VC2_, VC3_, VC4_]);
% Separando as matrizes A e B dos coeficientes:
system_A2 = [sol2.IL1_ == IL1_, sol2.IL2_ == IL2_, sol2.IL3_ == IL3_, sol2.IL4_ == IL4_,...
sol2.VC1_ == VC1_, sol2.VC2_ == VC2_, sol2.VC3_ == VC3_, sol2.VC4_ == VC4_];
vars2 = [ IL1, IL2, IL3, IL4, VC1, VC2, VC3, VC4 ];
vars22 = [ Vi ];
% Definindo as matrizes A2, B2, C2 e D2:
A2 = equationsToMatrix(system_A2,vars2);
B2 = equationsToMatrix(system_A2,vars22);
C2_ = [ 0; 0; 0; RseC4*Ro/(RseC4 - Ro); 0; 0; 0; -Ro/(RseC4 - Ro) ];
D2 = 0;
%% Equacionamento para o espaço de estados médio:
A = simplify(A1*D + A2*(1-D));
B = simplify(B1*D + B2*(1-D));
C = simplify(C1_*D + C2_*(1-D));
D = simplify(D1*D + D2*(1-D));
X = simplify(-inv(A)*B*Vi);
I = eye(8);
Tp = C*inv(s*I - A)*((A1-A2)*X + (B1-B2)*Vi)+(C1-C2)*X;
Without understanding the math in detail I can see that it slows at line 108 X = simplify(-inv(A)*B*Vi); rather than the last line, but I haven't been running it that long <1min. Try to utilize A\b instead of inv(A)*b which takes much more time.

Using FTSearch with date fields

I have code that will search particular fields in the document to find the values that the user selects and places those documents in a folder. I have the code working, but I'm stuck on how to proceed with doing the same thing with date fields. I need to be able to find documents within a date range. Can anyone help me with how to go about doing this? Here is the code that I have:
Sub Initialize
On Error GoTo ErrHandler
Dim ws As New NotesUIWorkspace
Dim session As New NotesSession
Dim db As NotesDatabase
Dim RemoveView As NotesView
Dim RemoveDoc As NotesDocument
Dim RemoveEntry As NotesViewEntryCollection
Dim dc As NotesDocumentCollection
Dim doc As NotesDocument
Dim view As NotesView
Dim j As Integer
Dim DialogDoc As NotesDocument
Set db = session.CurrentDatabase
Folder$ = "(UseOfForceSearch)"
'Clear folder before inputting current search results.
Set RemoveView = db.GetView(Folder$)
Set RemoveDoc = RemoveView.GetFirstDocument
If Not (RemoveDoc Is Nothing) Then
Set RemoveEntry = RemoveView.AllEntries
Call RemoveEntry.RemoveAllFromFolder(Folder$)
End If
If Not (db.IsFTIndexed) Then
answer = MessageBox(" Sorry. This database is not full-text indexed." + "Do you want to create an index?", MB_YESNO)
If (answer = IDYES) Then
Call db.UpdateFTIndex(True)
End If
End If
Set DialogDoc = db.Createdocument
searchForm$ = "$Force"
Form$ = "ReportDialog" 'Ask user for specifics of search using ReportDialog
Title$ = "Use of Force Search Criteria"
DialogDoc.Form = Form$
DialogDoc.StartDate = DialogDoc.StartDate(0)
DialogDoc.EndDate = DialogDoc.EndDate(0)
DialogDoc.Field1 = DialogDoc.Field1(0)
DialogDoc.Value1 = DialogDoc.Value1(0)
DialogDoc.Field2 = DialogDoc.Field2(0)
DialogDoc.Value2 = DialogDoc.Value2(0)
DialogDoc.Field3 = DialogDoc.Field3(0)
DialogDoc.Value3 = DialogDoc.Value3(0)
DialogDoc.Field4 = DialogDoc.Field4(0)
DialogDoc.Value4 = DialogDoc.Value4(0)
DialogDoc.Field5 = DialogDoc.Field5(0)
DialogDoc.Value5 = DialogDoc.Value5(0)
DialogDoc.Logic1 = DialogDoc.Logic1(0)
EnterDialog:
If (ws.DialogBox(Form$, True, True, False, True, False, False, Title$,DialogDoc,True)) Then
Else
Exit Sub
End If
SDate$ = CStr(DialogDoc.StartDate(0))
EDate$ = CStr(DialogDoc.EndDate(0))
Field1$ = UCase(CStr(DialogDoc.Field1(0)))
Field2$ = UCase(CStr(DialogDoc.Field2(0)))
Field3$ = UCase(CStr(DialogDoc.Field3(0)))
Field4$ = UCase(CStr(DialogDoc.Field4(0)))
Field5$ = UCase(CStr(DialogDoc.Field5(0)))
Oper$ = "contains"
Value1$ = UCase(CStr(DialogDoc.Value1(0)))
Value2$ = UCase(CStr(DialogDoc.Value2(0)))
Value3$ = UCase(CStr(DialogDoc.Value3(0)))
Value4$ = UCase(CStr(DialogDoc.Value4(0)))
Value5$ = UCase(CStr(DialogDoc.Value5(0)))
Logic1$ = UCase(CStr(DialogDoc.Logic1(0)))
Logic2$ = UCase(CStr(DialogDoc.Logic2(0)))
Logic3$ = UCase(CStr(DialogDoc.Logic3(0)))
Logic4$ = UCase(CStr(DialogDoc.Logic4(0)))
Set Date1 = New NotesDateTime(SDate$)
Set Date2 = New NotesDateTime(EDate$)
Date1ForReport$ = Date1.DateOnly
Date2ForReport$ = Date2.DateOnly
datemax = Date2.timedifference(Date1)
DaysBetween = datemax \ 86400
If(DaysBetween > (366 * 1)) Then
MessageBox "Date range cannot exceed 1 year.",48,"Error:"
GoTo EnterDialog
End If
For i = 1 To 1
searchForm$ = "(FIELD Form contains $Force) and "
Expr1$ = "FIELD " + Field1$ + " " + Oper$ + " " + Value1$
Expr2$ = "FIELD " + Field2$ + " " + Oper$ + " " + Value2$
Expr3$ = "FIELD " + Field3$ + " " + Oper$ + " " + Value3$
Expr4$ = "FIELD " + Field4$ + " " + Oper$ + " " + Value4$
Expr5$ = "FIELD " + Field5$ + " " + Oper$ + " " + Value5$
FinalExpr$ = searchForm$ + Expr1$
If(Logic1$ <> "") Then
FinalExpr$ = FinalExpr$ + " " + Logic1$ + " " + Expr2$
ElseIf (Logic2$ <> "") Then
FinalExpr$ = FinalExpr$ + " " + Logic1$ + " " + Expr2$ + " " + Logic2$ + " " + Expr3$
ElseIf (Logic3$ <> "") Then
FinalExpr$ = FinalExpr$ + " " + Logic1$ + " " + Expr2$ + " " + Logic2$ + " " + Expr3$ + " " + Logic3$ + " " + Expr4$
ElseIf (Logic4$ <> "") Then
FinalExpr$ = FinalExpr$ + " " + Logic1$ + " " + Expr2$ + " " + Logic2$ + " " + Expr3$ + " " + Logic3$ + " " + Expr4$ + " " + Logic4$ + " " + Expr5$
End If
FinalExpr$ = FinalExpr$
Print "Searching..."
' the number 16384 means fuzzy search
Set dc = db.FTSearch(FinalExpr$,0,,16384)
Folder$ = "(UseOfForceSearch)"
Call dc.PutAllInFolder(Folder$,True)
Next
Print "Search Completed with " + CStr(dc.Count) + " results."
Set view = db.getView(Folder$)
Exit Sub
ErrHandler:
MessageBox "Error" & Str(Err) & ": " & Error$,16,"Error!"
Exit Sub
End Sub
You can use operators = / < / > / <= / >= for date fields in FTSearch.
Example: FIELD YourDateField > 01/30/2013 or [YourDateField] > 01/30/2013.
To find documents within a date range you'd write:
[YourDateField] >= 01/01/2013 AND [YourDateField] <= 12/31/2013
Look here for a complete list of search options.

Run time error 9 when using arrary in Macro

I have been using the followng Macro and it works fine:
Sub PremTable()
Dim i, m, j As Integer
Dim PDFDiv, PDFClass, PDFSex, PDFPlan, LimAge As Variant
Dim FlagD, FlagC, Band, FlagP, FlagB, IssAge, Dur As Integer
PDFClass = Array("N", "S")
PDFSex = Array("M", "F")
PDFDiv = Array("G", "E")
PDFPlan = Array(10, 20, 30)
LimAge = Array(70, 60, 50)
j = 0
For FlagD = 1 To 2
Range("div").Value = PDFDiv(FlagD)
For FlagP = 1 To 3
Range("plan").Value = PDFPlan(FlagP)
For Band = 1 To 3
Range("band").Value = Band
For FlagS = 1 To 2
Range("sex").Value = PDFSex(FlagS)
For FlagC = 1 To 2
Range("class").Value = PDFClass(FlagC)
m = 18
For i = 1 To Range("LimAge").Value - 17
Range("IssAge").Offset(i + j, 0) = m
Range("age").Value = Range("IssAge").Offset(i + j, 0)
Worksheets("input").Range("J4:J76").Copy
Worksheets("Premium Tables").Range("M1").Offset(i + j, 0).PasteSpecial xlPasteValues, Transpose:=True
Range("DIV2").Offset(i + j, 0) = Range("Div")
Range("PLAN2").Offset(i + j, 0) = Range("plan")
Range("BAND2").Offset(i + j, 0) = Range("band")
Range("SEX2").Offset(i + j, 0) = Range("sex")
Range("CLASS2").Offset(i + j, 0) = Range("class")
m = m + 1
Next i
j = j + i - 1
Next FlagC
Next FlagS
Next Band
Next FlagP
Next FlagD
End Sub
Now I have another very similar spreatsheet that I want to use this macro to creat tables, but it always give me the "run time error 9" for all of the arrays having text format variables (for example: Range("class").Value = PDFClass(FlagC) causing an runtime error 9)
Please advise! Thanks very much!

programming a range of data : Matlab

I have this program, something related with statistic.
maximo = max(muestra);
minimo = min(muestra);
rango = maximo - minimo;
num_intervalo = round(1 + 3.322*log(length(muestra)));
amplitud = rango/num_intervalo;
rango_intervalo = [];
for i=1 : num_intervalo + 1
if i == 1
rango_intervalo(i: num_intervalo + 1) = minimo;
else
rango_intervalo(i: num_intervalo + 1) = rango_tabulado(i) + amplitud;
end
if i == num_intervalo + 1
rango_intervalo(i: num_intervalo + 1) = maximo;
end
end
rango_intervalo = rango_intervalo';
the intention is to create nine (or k intervals) intervals, where each interval has it ranges:
[1.580 - 2.587]
[2.587 - 3.594]
.
.
[9.636 - 10.650]
With code that I've programmed, it is resulting in 10 data not nine as per the intention.
Any idea, the improve this code?
Thanks.
How about:
intervals = linspace(minimo, maximo, num_intervalo + 1 );
intervals = [ intervals(1:end-1); intervals(2:end) ]';