- #1
gfd43tg
Gold Member
- 950
- 50
Homework Statement
Attached image
Homework Equations
The Attempt at a Solution
I am basing my code off a template I found in a textbook for using loops to create an array. If I didn't find this example I don't think I would even know where to begin with this. Here is what I came up with so far
Code:
levelVals = [10, 4, 7];
n = 2*size(levelVals,2) - 1;
m = 2*size(levelVals,2) - 1;
boxArray = zeros(n,m);
for k = 1:n
for h = 1:m
if k == levelVals(1)
boxArray(k,h) = k;
elseif h == 1
boxArray(k,h) = levelVals(1);
else
boxArray(k,h) = levelVals(2);
end
end
end
boxArray;
Here is boxArray
Code:
boxArray =
10 4 4 4 4
10 4 4 4 4
10 4 4 4 4
10 4 4 4 4
10 4 4 4 4
Basically I thought just to have an array with 5x5 dimensions and use loops to add elements to the array with the numbers desired.
Attachments
Last edited: