Plotting Two Consecutive Columns of Matrices
現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
古いコメントを表示
Hi,
I have 4 x 202 matrix, and I want to plot the columns in 2's e.g columns 1 and 2, next columns 3 and 4 as they represent X and Y coordinates. How can I do this?
Thanks
採用された回答
Star Strider
2021 年 12 月 21 日
First a (4 x 202) matrix defines a matrix of 4 rows and 202 columns. Assuming that it’s actually a (202 x 4) matrix, perhaps something like this —
M = randn(15, 4) % Prototype
M = 15×4
-1.4757 0.4730 -1.7963 0.5677
-1.4236 0.6301 -0.9039 -0.0171
-1.1303 1.3193 0.1080 0.2304
-1.2160 -0.9149 -0.3458 -1.0942
0.7360 0.9042 -0.1741 1.7954
0.1131 0.5694 1.0606 -0.2865
0.1741 -0.7245 -0.7010 1.2694
-1.8673 -0.5442 -0.6397 -2.0804
0.4837 0.0083 -0.6583 0.5971
-1.0150 -2.1755 0.5630 -0.2446
Mr = reshape(M, [], 2)
Mr = 30×2
-1.4757 -1.7963
-1.4236 -0.9039
-1.1303 0.1080
-1.2160 -0.3458
0.7360 -0.1741
0.1131 1.0606
0.1741 -0.7010
-1.8673 -0.6397
0.4837 -0.6583
-1.0150 0.5630
figure
plot(Mr(:,1), Mr(:,2), '.')

If the matrix actually is (4 x 202), transpose it first, then use the approach in this code example.
.
8 件のコメント
Femi O. Jinadu
2021 年 12 月 21 日
Thank you very much, it's not given the expected response yet. I probably didn't explain well enough.
The matrix is a 4 by 202 matrix. The first 2 columns and 4 rows are the location of an object at time 0, the next 2 columns (3 and 4) are the location at time 1, so it's like the same 4 points are converging towards something. I tried using a for loops can't seem to get it yet. See the image. The lines are meant to converge to the scatter plots which they are, but the way i constructed the for and while loops are creating some extra lines which aren't supposed to be there.
t

Femi O. Jinadu
2021 年 12 月 21 日
l= size(Xf) % Xf is the 4x202 matrix
for n=1:4
i=1
while i<=l(2)
plot(Xf(n,i:2:end-1),Xf(n,i+1:2:end))
i=i+1
end
end
I am not certain what the matrix is (not supplied), nor am I certain what the desired result is.
See if this produces the desired result —
M = randn(4, 16) % Prototype Matrix (Random)
M = 4×16
0.0752 -0.2438 -1.1305 0.5674 -0.8264 -0.8058 -0.0557 0.5916 0.5528 -0.7535 0.6855 -0.0317 -0.5626 -1.2305 -1.7698 -0.1324
-0.7432 0.4237 -1.8701 -1.1656 -1.3737 0.9483 1.0826 0.8271 1.4154 0.2680 1.7482 -0.3266 -0.7582 2.0894 -0.4560 0.2552
1.5404 0.1558 -0.9183 -0.8252 0.9294 -1.2118 -0.2726 1.3016 -0.1283 0.1639 -0.1338 0.1248 -0.1141 1.1451 -0.5234 -0.6048
-0.6458 0.2220 0.9233 0.0739 0.8112 -0.6546 -0.4364 0.6713 0.8739 -0.2792 -0.1227 1.6188 1.1815 -0.2486 -0.1096 0.5278
figure
hold on
for k = 1:2:fix(size(M,2))/2
colpair = [1 2]+(k-1) % Check Indices
xvct = M(:,colpair(:,1)) % Check X-Vector
yvct = M(:,colpair(:,2)) % Check Y-Vector
plot(M(:,colpair(:,1)), M(:,colpair(:,2)), '.-')
end
colpair = 1×2
1 2
xvct = 4×1
0.0752
-0.7432
1.5404
-0.6458
yvct = 4×1
-0.2438
0.4237
0.1558
0.2220
colpair = 1×2
3 4
xvct = 4×1
-1.1305
-1.8701
-0.9183
0.9233
yvct = 4×1
0.5674
-1.1656
-0.8252
0.0739
colpair = 1×2
5 6
xvct = 4×1
-0.8264
-1.3737
0.9294
0.8112
yvct = 4×1
-0.8058
0.9483
-1.2118
-0.6546
colpair = 1×2
7 8
xvct = 4×1
-0.0557
1.0826
-0.2726
-0.4364
yvct = 4×1
0.5916
0.8271
1.3016
0.6713
hold off

This reports the results of each loop iteration as well as plots them, so check to be certain it references the appropriate matrix columns and produces the desired result (since I still have no idea what that is). First, use a subset of the maatrix, for example the first 16 columns as I did here (there must be an even number of columns). If that works, see if the entire matrix plots correctly.
.
Femi O. Jinadu
2021 年 12 月 21 日
Still no luck, here's the data though. Thanks a lot
Star Strider
2021 年 12 月 21 日
No luck, indeed!
I have no idea which of those 155 variables is the one to work with. My guess would be ‘Xf’ or‘Xf1’ so I’ll wait for confirmation before I proceed.
Meanwhile, what does ‘no luck’ mean? What should the code do? (I still have absolutely no idea.)
.
Femi O. Jinadu
2021 年 12 月 21 日
I'm sorry, Xf.
We have 4 rows, and 202 columns. Each row represents a node and the node location (coordinates) are changing - like column 1 and column 2 are the first cordinates of the 4 nodes, the next 2 columns are the next location, etc.
Femi O. Jinadu
2021 年 12 月 21 日
Hi, thanks
I've figured it out, thanks so much.
Star Strider
2021 年 12 月 21 日
My pleasure!
If my Answer helped you solve your problem, please Accept it!
.
その他の回答 (1 件)
Chunru
2021 年 12 月 21 日
x = rand(202, 4); % 202x4 (not 4x202)
plot(x(:,1), x(:, 2), 'ro', x(:,3), x(:, 4), 'b*')

カテゴリ
ヘルプ センター および File Exchange で Numerical Integration and Differentiation についてさらに検索
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の MathWorks のサイトは、お客様の地域からのアクセスが最適化されていません。
南北アメリカ
- América Latina (Español)
- Canada (English)
- United States (English)
ヨーロッパ
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
