How to plot rectangles using variables
7 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
採用された回答
the cyclist
2022 年 10 月 30 日
編集済み: the cyclist
2022 年 10 月 30 日
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
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Annotations についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!