Hi,
I was trying to "convert" this matlab *.m file that I have to excel vba but just don't have enough knowledge to do so in regard.
What i'm trying to do here is to plot a value of x against time.
![]()
%MATLAB m script a = 5; b = 3; c = 7; t = 0.1; x(1) = 0.3; x(2) = 0.2; for i=2:79 x(i+1) = (a*x(i-1)-(b/(t*t))*x(i-1)+x(i)+ t*x(i)) / (b/(t*t) + c/t); end plot(x);
vba attempt:
And then when the cells are populated by the values of x I would plot them against, say b1:b78, which would be time t+t, to get my graph.![]()
Sub calc() Dim i As Integer Dim a, b, c, x(1 To 79) As Double a = 5 b = 3 c = 7 t = 0.1 x(1) = 0.3 x(2) = 0.2 For i = 2 To 78 x(i + 1) = (a * x(i - 1) - (b / (t * t)) * x(i - 1) + x(i) + t * x(i)) / (b / (t * t) + c / t) Next i Cells(1, 1).Value = x() <------ what should i put here so that all the values of x in the range from 1 to 78 would populate cells a1 to a78? because all that is doing is outputting only one value in that particular cell. End Sub
ANY help would be appreciated.
Thanks.
Bookmarks