How to get Matlab to multiply different columns in a for loop based upon an if/else statement? -



How to get Matlab to multiply different columns in a for loop based upon an if/else statement? -

so attempting apply late penalty , penalty scheme onto just-in time business system. have 4 columns in original matrix, , infinite amounts of orders coming in. 1 column represents due date, column represents late penalty fee , lastly column represents penalty fee.

order | due date | penalty | late penalty 1 10/12/14 $8 per day $2 per day 2 10/2/14 $5 per day $6 per day 3 10/6/14 $1 per day $4 per day .... ........ ...... ......

if difference in days between due date , current date greater zero, order , multiply penalties difference in days. if difference in days between due date , current date less zero, order late , multiply late penalties difference in days.

my code keeps coming zeros matrix, not sure doing wrong. have far:

temp = zeros(m,2); t=1:m u=12:13 if daysdifference > 0 sumearly = a(t,12)*daysdifference temp(t) = sumearly + temp(t) elseif daysdifference < 0 sumlate = a(t,13)*daysdifference temp(t) = sumlate + temp(t) end end end

i not know how store data, created own array of cells

data = { ... 1, '10/12/14', 8, 2; 2, '10/2/14', 5, 6; 3, '10/6/14', 1, 4 ... }; results = zeros(size(data, 1), 1); = 1 : size(data, 1) days = ceil(datenum(data{i,2}, 'mm/dd/yy') - now); if days > 0 results(i) = results(i) + days * data{i, 3}; elseif days < 0 results(i) = results(i) + days * data{i, 4}; end; end;

result

48 -24 0

matlab

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -