Use equation in for loop
Mostra commenti meno recenti
I have a 2d array that I'm reading in that is 100x2. I have the following equation that needs to loop through and calculate starting at the next row
total=total+(y1+y2)*(x1-x2)
Here's what I've started with, I'm just not sure how to set it up
[nrows,ncols] = size(data);
for m=1:1:nrows
for n=1:1:ncols
total = total+
2 Commenti
Walter Roberson
il 4 Mag 2016
What are x1, x2, y1, y2? How do they relate to the content of the image? How do they relate to the row or column numbers?
Risposta accettata
Più risposte (2)
CS Researcher
il 4 Mag 2016
Modificato: CS Researcher
il 4 Mag 2016
You can avoid the for loop by:
data = rand(100,2); % just for an example
N = size(data,1);
total = sum((data(1:N-1,2) + data(2:N,2)) .* (data(1:N-1,1) + data(2:N,1)));
Categorie
Scopri di più su Loops and Conditional Statements in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!