how to iterate?

2 visualizzazioni (ultimi 30 giorni)
JULIET OSUNDE
JULIET OSUNDE il 7 Gen 2021
Commentato: JULIET OSUNDE il 7 Gen 2021
Hello, I am new to matlab and in need of help. I have a 43200 x 2 matrix and having difficulty writting a code for this equation: Y=A+(D+C/2)*1, Z=Y-B. where A is -120449852, D=3311.5705, C=1476.9455, B=-10749852 from the data shown below.Please how do i code this in such a way that it repeats this operation for all the elements in the matrix sequentially and saves Z values for each iteration. for example, the next vaule of A=-107496428, D=1476.9455, C=-1719.7385 and B=-117996722 and so on...
Please note that data sample shown below is for first epoch,each epoch ends with zeros at the bottom, kindly bear this in mind while coding. Thanks
Data
-120449852 3311.5705
-107496428 1476.9455
-117996722 -1719.7385
-120627169 -1228.7064
-116870191 -3087.5875
-134480051 -125.6097
-125355131 3313.2842
-126744025 994.96613
-112248639 937.16468
-130631487 -3113.0687
-108469847 -191.42345
0 0

Risposta accettata

Stephen23
Stephen23 il 7 Gen 2021
I don't see why any iterations are required, vectorized code will do this quite easily:
A = [-120449852, -107496428];
B = [-10749852, -117996722];
C = [1476.9455, -1719.7385];
D = [3311.5705, 1476.9455];
Y = A+(D+C/2)*1
Y = 1×2
-1.2045 -1.0750
Z = Y-B
Z = 1×2
-1.0970 0.1050
  5 Commenti
Stephen23
Stephen23 il 7 Gen 2021
M = [...
-120449852 3311.5705
-107496428 1476.9455
-117996722 -1719.7385
-120627169 -1228.7064
-116870191 -3087.5875
-134480051 -125.6097
-125355131 3313.2842
-126744025 994.96613
-112248639 937.16468
-130631487 -3113.0687
-108469847 -191.42345
0 0];
A = M(1:end-1,1);
B = M(2:end ,1);
C = M(1:end-1,2);
D = M(2:end ,2);
Y = A+(D+C/2)*1
Y = 11×1
-1.2045 -1.0750 -1.1800 -1.2063 -1.1687 -1.3448 -1.2535 -1.2674 -1.1225 -1.3063
Z = Y-B
Z = 11×1
-0.1295 0.1050 0.0263 -0.0376 0.1761 -0.0912 0.0139 -0.1449 0.1838 -0.2216
JULIET OSUNDE
JULIET OSUNDE il 7 Gen 2021
Thank you Stephen, It worked!

Accedi per commentare.

Più risposte (0)

Tag

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by