I want to loop an equation over multiple rows
Afficher commentaires plus anciens
I know how to do this in excel but not in Matlab.
I have a huge matrix and in that I want to create a equation for only three column( a,b and c) s, but on every row. I want it to add a column with the answers to the equation(x).
The equation is x=a*b^c
In each row of columns a b and c the integers are different, so I can't use a simple number instead.
I am thinking the answer to this is a for loop but I am a begginer at Matlab so may be wrong.
In excel the way i would do this is create the equation in the top row and drag down,if that makes sense.
Réponse acceptée
Plus de réponses (1)
Image Analyst
le 15 Août 2021
Try this;
columnsToProcess = [4, 9, 17]; % Whatever....
[rows, columns] = size(x); % Size of original matrix.
for col = columnsToProcess % Process only these particlar columns.
for row = 1 : rows
% Get the a, b, and c parameters.
% These vary on a row-by-row basis.
a = however you get it.
b = however you get it.
c = however you get it.
x(row, col) = a * b ^ c;
end
end
Catégories
En savoir plus sur Loops and Conditional Statements dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!