For Loop: Help me PLZ

3 Ansichten (letzte 30 Tage)
Anthony Kubik
Anthony Kubik am 28 Nov. 2020
Kommentiert: nehemiah hofer am 29 Nov. 2020
I have a 96x3 matrix. Each column represents a different variable in an equation. Each row represents the set of the three variables in the equation. I need to write a for loop that can print a list of the answers of all 96 equations. If this makes sense can anyone help??
  4 Kommentare
Walter Roberson
Walter Roberson am 29 Nov. 2020
for rowidx = 1 : size(Matrix,1)
result(rowidx) = f(Matrix(rowidx, 1), Matrix(rowidx, 2), Matrix(rowidx,3) )
end
nehemiah hofer
nehemiah hofer am 29 Nov. 2020
So i get an error message here im not sure where I am going wrong. I was replacing matrix for my matrix name and it seems to have a problem with result? This is what I am putting.
txt = readmatrix("ec.txt");
for rowidx = 1 : size(txt,1)
result(rowidx) = f(txt(rowidx, 1), txt(rowidx, 2), txt(rowidx,3) )
end
Thanks again for the assistance

Melden Sie sich an, um zu kommentieren.

Antworten (1)

M.Many
M.Many am 28 Nov. 2020
You can just use
sum(M) % it sums the columns
Or if you absolutely need to use a for loop, you can do
sum = [];
for k = 1:size(M,1)
sum = sum+ M(k,:)
end
  6 Kommentare
Anthony Kubik
Anthony Kubik am 28 Nov. 2020
Ok, i am a college student taking my first coding class that honestly does not know what i am being asked either. But i will try and put it into better terms. I have a 96x3 matrix, each row is three variables that make an equation. I need a for loop that will do each of the 96 equations, and give me a list of 96 answers to each individual equation. From the picture, i need a list of
x=r(1,1),y=r(1,2),z=r(1,3) put into the equestion
x=r(2,1), y=r(2,2),z=r(2,3)
Where the row increases to 96. Hope this makes more sense, really pareciate the help.
I also added a picture of my matrix.
Walter Roberson
Walter Roberson am 28 Nov. 2020

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Tags

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by