| Thread Closed |
Building a matrix using "while" loops? (MATLAB) |
Share Thread | Thread Tools |
| Feb8-10, 05:43 AM | #1 |
|
|
Building a matrix using "while" loops? (MATLAB)
Hello
Here is my code: Code:
i = 1;
j = 1;
S = zeros(11,11);
while i < 12
while j < 12
S(i,j) = Test1(a(i,j),b(i,j),c(i,j));
j = j + 1;
end
i = i + 1;
end
My code is only calculating the first row of S, ie. S(2,1) = 0 still. I don't know why the program is ending without adding 1 onto i and repeating the loop, I can only imagine the "while" loop is the wrong way of going about this? Thanks for any help, Mike |
| PhysOrg.com |
science news on PhysOrg.com >> Hong Kong launches first electric taxis >> Morocco to harness the wind in energy hunt >> Galaxy's Ring of Fire |
| Feb8-10, 09:52 AM | #2 |
|
Mentor
|
A better choice is a for loop for each of your loops.
Code:
for i=1:11
for j = 1:11
%% loop body
end
end
Code:
while i < 12
j = 1 %% added this line
while j < 12
S(i,j) = Test1(a(i,j),b(i,j),c(i,j));
j = j + 1;
end
i = i + 1;
end
|
| Thread Closed |
| Thread Tools | |
Similar Threads for: Building a matrix using "while" loops? (MATLAB)
|
||||
| Thread | Forum | Replies | ||
| Help me design my "carputer" to work in the cold (advice on building a heater) | Computing & Technology | 10 | ||
| building a "hybrid" and dynamic mathematical space | Math & Science Software | 0 | ||
| New Loll "The Art of Building Spacetime" (Oriti's book) | Beyond the Standard Model | 0 | ||
| building a "hybrid" and dynamic mathematical space | Math & Science Software | 0 | ||
| "The Duel: Strings versus Loops" by Rudy Vaas | Beyond the Standard Model | 9 | ||