Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] how to get the sum of the difference of an output and a data set

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 manipulate the output from a for loop do summation of differences between that output and a data set. An example is shown below. I tried it but it only computed the sum for the first for loop neglecting the other data set.

Code:
Code:
  for f = [1   4    8    10   14];
    b=2;
    c=1;
    d=1;
    n=4;
    N= f*b*c*d;
    M=[4.5    10.5   20.5   25.6   30.8];
    Y = (M-N);
    A = sum(Y);
  end
  disp(A)
 

I didn.t understand what exactly you want to do. I don't think you need a for loop.
I modified your original code to the following:


Code:
f = [1 4 8 10 14];
b=2;
c=1;
d=1;
n=4;
N= f*b*c*d;
M=[4.5 10.5 20.5 25.6 30.8];
Y = (M-N);
A = sum(Y);
disp(A)

you'll have
Code:
f(1)=1
f(2)=4
f(3)=8
f(4)=10
f(5)=14

then

Code:
N(1) = 1*b*c*d
N(2) = 4*b*c*d
N(3) = 8*b*c*d
N(4) = 10*b*c*d
N(5) = 14*b*c*d

doing the calculation, the following error will be calculated:

Code:
Y(1) = 2.5
Y(2) = 2.5
Y(3) = 4.5
Y(4) = 5.6
Y(5) = 2.8
but if you sum all this values of course you'll get a single value that is 17.9.

Is this what you expected ?
 

To subtract the output of a for loop manipulation sequentially from a data set

[MODERATED] Thread duplicated, merged with the above


Please i need hint on how to make the output of this for loop (N) to be subtract from M sequentially without skipping any of the numbers. I tried this code and it did not give me the correct answer as it ignored some numbers.
Code:
for f = [1   4   8   10  14  18   22  26  30  34  38  42  45  48   52];
    b=2;
    c=1;
    d=1;
    N= f*b*c*d;
end 
M=[4.5  10.5   20.5   25.6  30.8  34.6  35.8  38.4  17.2   18.5  20.5  22.6  24.5  26.6 28.9];
Y = (M-N);
A = sum(Y);
disp(A)
 
Last edited by a moderator:

Re: To subtract the output of a for loop manipulation sequentially from a data

I assume you know the basics of MATLAB.

If not write your problem by explicit example, rather than force us to assume we know what you are doing or know what you want.

https://www.maths.uq.edu.au/department/computing/matlab/
 

Re: To subtract the output of a for loop manipulation sequentially from a data

The first row of the code above do not seem a typical MATLAB construction for a loop.

Anyway, once this thread duplicates another recent discussion that shegmite created having the same subject, this one will be closed. Please refer to this :
how to store horizontally the output of a multiplication for subtraction later
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top