How to plot rectangles using variables
5 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I'm trying to plot several rectangles with data from an array, and i can't quite figure out how to plot this way
The code i've been trying:
T = testarray;
x1 = T(1:216,1);
y1 = T(1:216,2);
w1 = T(1:216,3);
h1 = T(1:216,4);
x = table2array(x1);
y = table2array(y1);
w = table2array(w1);
h = table2array(h1);
rectangle('Position',[x(1:216,1) y(1:216,1) w(1:216,1) h(1:216,1)])
axis([-1 2 -1 2])
Any idea what i'm doing wrong? I keep getting the error "Error using rectangle
Value must be a 4 element vector"
0 commentaires
Réponse acceptée
the cyclist
le 30 Oct 2022
Modifié(e) : the cyclist
le 30 Oct 2022
Are you trying to plot 216 rectangle with that one line? If you look at the documentation, you will see that you cannot do that. It is expecting a single 4-element vector, not an array.
You need to loop over your arrays. (If that is, indeed, what you are trying to do.) Here is how you can do that. I just used 6 rectangles, and pretend data.
N = 6;
testarray = array2table(rand(N,4));
T = testarray;
x1 = T(1:N,1);
y1 = T(1:N,2);
w1 = T(1:N,3);
h1 = T(1:N,4);
x = table2array(x1);
y = table2array(y1);
w = table2array(w1);
h = table2array(h1);
figure
hold on
for nr = 1:N
rectangle('Position',[x(nr) y(nr) w(nr) h(nr)])
axis([-1 2 -1 2])
end
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Creating, Deleting, and Querying Graphics Objects dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
