excelmatlabvectorapplescriptiwork

Creation of vector of unknown size in Excel


I am attempting to translate my existing Matlab code into Numbers (basically Excel). In Matlab, I have the following code:

clear all; clc;
n = 30
x = 1:(n-1)
T = 295;

D = T./(n-x)

E = T/n

for i=1:(n-2)
    C(i) = D(i+1) - D(i)
end

hold on
plot(x(1:end-1), C, 'rx')
plot(x, D, 'bx')

I believe everything has been solved by your formulas, there are parts of them that I don't understand otherwise I would try to figure the rest out myself. Attached is the result (Also you might like to know that the formulas you gave work and are recognized in Numbers). Im trying to figure out why (x) begins at 2 as I feel as though it should start at 1?

Also it is clear that the realistic results for the formulas only exist under certain conditions i.e. column E > 0. That being the case, what would be the easiest way to chart data with a filter so that only certain data is charted?

enter image description here


Solution

  • (Using Excel...)

    Suppose you put your input values T & n in A1 & B1 respectively.

    You could generate x, D & C In columns C,D & E with:

    C1: =IF(ROW()<$A$1,ROW(),"")

    D1: =IF(LEN(C1)>0,$A$2/($A$1-C1),"")

    E1: =IF(LEN(D2)>0,D2-D1,"")

    You could then pull all 3 columns down as far as you need to generate the full length of your vectors. If you then want to chart these, simply use these columns as inputs.