Plotting a matrix of line plots

조회 수: 9 (최근 30일)
Manas Pratap
Manas Pratap 2021년 11월 12일
댓글: Image Analyst 2021년 11월 14일
Hi!
I have to plot multiple line plots in a matrix. So for example, consider that I have 2 variables x and y and I have 3 data sets of each, i.e x1y1 x2y2 x3y3.
I need to plot this data in a matrix form of 6x6, i.e 36 individual graphs. There's an image of the expected graph below. Any help is much appreciated!
  댓글 수: 7
Manas Pratap
Manas Pratap 2021년 11월 13일
The x and y axis should only come up on the sides of the entire image, not individually for each plot
Image Analyst
Image Analyst 2021년 11월 13일
@Manas Pratap, did you see my second answer where I turned off those axes?

댓글을 달려면 로그인하십시오.

답변 (4개)

KSSV
KSSV 2021년 11월 12일
x1 = rand ; y1 = rand;
x2 = rand ; y2 = rand ;
x3 = rand ; y3 = rand ;
[X,Y] = meshgrid([x1 y1 x2 y2 x3 y3]) ;
  댓글 수: 2
Manas Pratap
Manas Pratap 2021년 11월 12일
It didnt plot anything..
KSSV
KSSV 2021년 11월 12일
plot(X,Y,'k',X',Y','k')

댓글을 달려면 로그인하십시오.


Image Analyst
Image Analyst 2021년 11월 12일
Try subplot(). Adapt as needed.
numPoints = 10;
v1 = sort(rand(1, numPoints));
v2 = sort(rand(1, numPoints));
v3 = sort(rand(1, numPoints));
v4 = sort(rand(1, numPoints));
v5 = sort(rand(1, numPoints));
v6 = sort(rand(1, numPoints));
% Concatenate
v = {v1;v2;v3;v4;v5;v6}
rows = numel(v)
for k1 = 1 : rows
for k2 = 1 : rows
thisx = v{k1};
thisy = v{k2};
subplot(rows, rows, rows*(k1-1)+k2)
plot(thisx, thisy, 'b-', 'Linewidth', 2)
grid on;
drawnow;
end
end

Yusuf Suer Erdem
Yusuf Suer Erdem 2021년 11월 12일
x1 = rand; y1 = rand;
x2 = rand; y2 = rand;
x3 = rand; y3 = rand;
[X,Y] = meshgrid([x1 y1 x2 y2 x3 y3]);
plot(X,Y)
Add plot(X,Y) command below it.

Image Analyst
Image Analyst 2021년 11월 13일
@Manas Pratap since you said in a comment "The x and y axis should only come up on the sides of the entire image, not individually for each plot", you can turn the tick marks off except in the first column or last row:
numPoints = 10;
v1 = sort(rand(1, numPoints));
v2 = sort(rand(1, numPoints));
v3 = sort(rand(1, numPoints));
v4 = sort(rand(1, numPoints));
v5 = sort(rand(1, numPoints));
v6 = sort(rand(1, numPoints));
% Concatenate
v = {v1;v2;v3;v4;v5;v6}
rows = numel(v)
for k1 = 1 : rows
for k2 = 1 : rows
thisx = v{k1};
thisy = v{k2};
subplot(rows, rows, rows*(k1-1)+k2)
plot(thisx, thisy, 'b-', 'Linewidth', 2)
grid on;
drawnow;
% Turn off y axis except if it's the first column.
if k2 > 1
yticks([]);
end
% Turn off x axis except if it's the last row.
if k1 < rows
xticks([]);
end
end
end
  댓글 수: 4
Manas Pratap
Manas Pratap 2021년 11월 13일
Getting an error
Execution of script scatter as a function is not supported:
Error in scatter (line 68)
scatter(thisx, thisy, 'filled')
Image Analyst
Image Analyst 2021년 11월 14일
Scatter is not a script. It's a built in function. You did not name your script "scatter.m" did you? You can't (or shouldn't) name your script after built-in functions like scatter or else you cannot run those built-in functions anymore.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by