Plotting Two Consecutive Columns of Matrices
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
0 개 추천
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
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

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.
.
Still no luck, here's the data though. Thanks a lot
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.)
.
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.
Hi, thanks
I've figured it out, thanks so much.
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!웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 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)
