3

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

Sterling Butters
  • 1,024
  • 3
  • 20
  • 41
  • Can you provide more details? Show how you intend to use this "vector" – Amit Jul 31 '15 at 19:07
  • Just edited my question, hopefully more clear now – Sterling Butters Jul 31 '15 at 19:40
  • Actually its less clear now. I was under the impression this question was about Excel. Now it's not. And you still didn't show how you plan to use the vector, or what it should look like. Your matlab code might be helpful for someone with matlab background, but means nothing to other who know nothing of it, but might have a lot of knowledge in Excel (Me :-) – Amit Jul 31 '15 at 19:52
  • Its become less about Excel now since I'm using Numbers with the iWork Suite and I didn't anticipate this level of intensity i.e. macros and applescript. The vector/column example is now shown in the figure with the ellipsis indicating the consecutive numbers from 1 to (n-1) – Sterling Butters Jul 31 '15 at 20:03
  • I am accepting help for either Numbers or Excel as once I get a working document going I won't really care what software – Sterling Butters Jul 31 '15 at 20:04
  • I also understand the fact that n in the figure is taking the value of 0 however the majority of the time it will possess a different value that would make conceptualizing everything easier i.e. {(n-1) @ (n=0)} = -1 is not the focus of the calculations – Sterling Butters Jul 31 '15 at 20:07
  • OK, so you want a running number going down the rows.. that was actually the easy part to understand. What do you want to do with these cells though? and what is that "Days left(n)" supposed to mean (How is that an input to generate/control the length of x)? – Amit Jul 31 '15 at 20:08
  • As you might be able to deduce from the matlab code, x is a vector from 1 to (n-1) where (n-1) is the length of the vector. The entire goal here is to be able to graph both "D" and "C(i)" as a function of x. So, first, I am trying to take T (in the matlab code) and divide it by the difference of (n) and each subsequent number in the vector (x), and create a new vector/column (D) of the same length. n is a feature that changes based on time which you might deduce from the date formatting below (n) therefore (n-1) will also change based on the day. More clear? – Sterling Butters Jul 31 '15 at 20:18
  • So your inputs are "n" & "T" (and in the sample, 30 & 295 respectively), and from that you want to generate a series (vector..) "D" which is [295/29, 295/28, 295/27,...,295/1], and then "C" which is C(i) = D(i+1) - D(i) == [295/28 - 295/29, 295/27 - 295/28,...,295/1 - 295/2]. Is that it? – Amit Jul 31 '15 at 20:28
  • That's exactly it!!! – Sterling Butters Jul 31 '15 at 20:55

1 Answers1

0

(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.

Community
  • 1
  • 1
Amit
  • 45,440
  • 9
  • 78
  • 110