I’m trying to do a simple script but I can’t seem to get it to do what I want! I’m very new to codewriting so I’m probably just missing something that’s obvious to other people, the code looks like this:
n=1; i=1; A=size(Production); CasesToCompare=A(2); while i<=CasesToCompare while n<=length(Consumption)if Consumption(n)>Production(n,i) Cost(n,i)=(Consumption(n)-Production(n,i)).*BuyPrice(n);else Cost(n,i)= -((Production(n,i)-Consumption(n)).*SellPrice(n));endn=n+1;endi=i+1end
I have data in my workspace called Consumption, Production, SellPrice, BuyPrice and what Im trying to do is first running the if/else statement through all the rows in the first column of Production and Consumption and saving it in the first column of a variable called Cost and then go to the next column of the Production variable (while still staying in the first column of the Consumption variable) and running through its rows and saving the results in the second column of “Cost”.
But the problem is that after the script Is done the output variable “Cost” only has one column. What am I doing wrong? Why does the number of columns in “Cost” not increase when “i” increases?
Thanks
Best Answer