自动为矩阵的每一列绘制图形中的子图 [英] Plotting subplots in a figure automatically for each column of matrix

查看:111
本文介绍了自动为矩阵的每一列绘制图形中的子图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如,假设我有一个带有colheaders(<1x6 cell>)的跟随矩阵(<9x6 double>).

For example let's say I have a following matrix (<9x6 double>) with a colheaders(<1x6 cell>).

 Matrix =

   226.7431   14.7437   14.9417   14.1000   14.5000       66.0590   
   226.7500   14.6582   14.8250       NaN   14.2000       66.7740   
   226.7569   14.3590   14.6067       NaN   13.9000       68.4897   
   226.7639   14.2702   14.5717   13.4000   13.8000       68.2487   
   226.7708   14.2555   14.6000       NaN   14.0000       NaN        
   226.7778   14.1605   14.5967       NaN   13.9000       NaN      
   226.7847   14.0320   14.4567   12.9000   13.6000       68.8272   
   226.7917   13.8422   14.2733       NaN   13.4000       69.6392   
   226.7986   13.6585   14.1169       NaN   13.1000       69.8048   

我想在带有子​​图的matlab图中将矩阵的第一列绘制在x轴上,将其余部分绘制在y轴上(假设一个图中为3).我可以手动执行类似这样的操作,等等.

I want to plot first column of matrix on x-axis and the rest on y-axis in a matlab figure with subplots (let's say 3 in one figure). Manually I can do something like this a figure and so on.

figure
subplot(3,1,1)
plot(Matrix(:,1),Matrix(:,2),'ro'); grid on; box on; xlabel('A');ylabel('B')
subplot(3,1,2)
plot(Matrix(:,1),Matrix(:,3),'bo'); grid on; box on; xlabel('A');ylabel('C')
subplot(3,1,3)
plot(Matrix(:,1),Matrix(:,4),'go'); grid on; box on; xlabel('A');ylabel('D')
and so on.....
......
......

现在开始一个棘手的部分,在这个部分中,我需要像你们这样的专家的帮助.我不想对我的矩阵进行手动绘制,因为它包含200列.因此,我想对矩阵进行自动绘制,以便它在子图中绘制矩阵的每一列.但是200个子图不能包含一个数字,因此它会在子图限制后自动开始一个新的数字(假设为3).另外,我还需要使用头文件"colheaders"自动定义"xlabel,ylabel,legend".是否有可能?

Now here start a tricky part in which I required help from experts like you guys. I do not want to do manual plotting for my matrix as it consists on 200 columns. So what I want to do a automatic plotting of matrix, so that it plot every column of matrix in subplots. But 200 subplot can not come in one figures, so it start automatically a new figure after subplots limit(let's say 3). Beside I also need to define 'xlabel, ylabel,legend' automatically with a header file 'colheaders'. Is it possible?

推荐答案

x = rand(10, 200);
myYLabel = char(64+randi(26, 200, 1));

nrows = 3;
ncols = 2;
for ii = 1:size(x, 2)
    if nrows*ncols-mod(-ii, nrows*ncols) == 1
        figure;
    end
    subplot(nrows, ncols, nrows*ncols-mod(-ii, nrows*ncols));
    plot(x(:, ii));
    ylabel(myYLabel(ii, :));
end

这篇关于自动为矩阵的每一列绘制图形中的子图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆