How to generate rectangles based on coordinates in a randomized matrix?
Show older comments
So I have a matrix. Currently it looks like this:
S.matrix =
2 78 46
1 148 148
3 431 431
1 224 224
1 595 595
3 58 58
1 160 160
1 244 244
1 410 410
1 526 526
Now I have code that makes this matrix random, meaning the numbers are all random (as long as they are between 1 and 640) as well as the size. The amount of columns stay the same, but the rows are not set. My current code has it that as longs as a certain condition is fulfilled, a new row to the matrix is added, hence the ambigous size. For the sake of debugging, I set the condition to a certain point such that the code will always produce a 3x10 matrix.
if S.matrix(:,1) == 1
S.blasterEM = rectangle("Position",[S.matrix(:,2) S.matrix(:,3) 5 10]);
S.blasterEM.FaceColor = [1 0 0];
S.blasterEM.EdgeColor = NA;
elseif S.matrix(:,1) == 2
S.sniperEM = rectangle("Position",[S.matrix(:,2) S.matrix(:,3) 5 15]);
S.sniperEM.FaceColor = [1 0 1];
S.sniperEM.EdgeColor = NA;
elseif S.matrix(:,1) == 3
S.chaserEM = rectangle("Position",[S.matrix(:,2) S.matrix(:,3) 5 20]);
S.chaserEM.FaceColor = [0 1 0];
S.chaserEM.EdgeColor = NA;
end
This code runs if statements depending on the first column and is supposed to produce rectangels according to the corresponding row. For example, S.matrix(1,1) will produce a specific type of rectangle at coordinates (78, 46). However, not only are the rectangles not showing up in the figure, I believe the rectangles aren't being produced at all. Is there a way I can make the if statements more precise such that any time the column at S.matrix(:,1) fulfills the parameters of the if statement, it will produce a rectangle at the corresponding coordinates? I also want to be able to make it so that the it will produce rectangles no matter the N of a 3xN matrix.
Any help is appreciated. Sorry if my problems seems a bit confusing to understand. Comment any misunderstandings, and I will do my best to answer.
Accepted Answer
More Answers (0)
Categories
Find more on 2-D and 3-D Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!