how to store horizontally the output of a multiplication for subtraction later

Status
Not open for further replies.

shegmite

Member level 1
Joined
Apr 8, 2012
Messages
33
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
1,496
Please i need hint on how to store the output from a for loop multiplication horizontally and then subtract it from a data set arranged horizontally to get the sum .An example is shown below though not the whole manipulation code. I want the computer to do the subtraction as :
20.5-5.2 , 30.6-10.3, 40.6-20.5 and so on and then sum the differences.An illustration of what i want is shown below.
Code:
 % output from  a  for  loop needed to be stored horizontally as 
Au = 5.2    10.3    20.5   30.4   45.6   50.6   55.7   60.8   75.8   80.9 
 %  data  set to be subtracted typed  horizontally as
Ab = [20.5   30.6   40.6   50.7   60.6   70.8   80.8   90.9   97.9   90.2];
Y = (Ab-Au);
Z = sum(Y);
disp(Z)
 
Last edited by a moderator:

Why not manually make another loop to perform the accumulated sum of all the elements of the resulted array Y ?
 

Please could you explain better or if possible you can post the syntax to use .
 

Something like that (not tested) :

Code:
Z= 0;
for k =1:length(Y)
     Z = Z + Y(k)
end
 

What is the difference of this post with respect to your previous one:" how to get the sum of the difference of an output and a data set" ?
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…