Matlab在gui中的多个子图
Matlab multiple subplots in gui
我目前正在 Matlab Gui 中研究多元回归。我有一个名为 A 的变量和一个名为 X 的矩阵,其中包含许多列,表示为 X1、X2、...Xn。我想制作一个图,其中有子图 (每行 2 个),图在 A 和每个 X[=26 之间=] 列。问题是,当用户插入他的 X 矩阵时,该列可能是 1、2 或 10。我想我必须为 X 做一个 for 循环。这在子图中是否可能?我在想类似的事情。有人可以帮我让它工作吗?
cols = size(X,2);
figure;
for i = 1:cols
subplot(ceil(cols/2),2,i)
scatter(A,X(i,:));
end
我想要的输出必须在 Y 轴中具有 向量 A 的子图以及矩阵 X 的每一列。即如果 X 有 5 列,我想要一个有 5 个子图的图形。
是的,你可以。下面是演示。
引用自subplot:
subplot(m,n,p) divides the current figure into an m-by-n grid and creates axes in the position specified by p.
因此,您的 a
应该是总列数除以 2。但是,这可能会导致奇数列为非整数。您需要用 ceil
.
randomColNum = randi([1,10]);
randomRowNum = randi([10,20]);
A = rand(1,randomRowNum ); % make a random vector to imitate matrix A.
X = rand(randomRowNum, randomColNum ); % make a random matrix to imitate user input X.
cols = size(X,2);
figure;
for i = 1:cols
subplot(ceil(cols/2),2,i)
scatter(X(:,i), A);
end