0

我在函数中有一个带有浮点值的NxM矩阵。W

我希望能够在图中显示X每列迭代的演变。

伪代码将是:

- open a window to show all values of column 1 of W..
- open a window to show all values of column 2 of W..
... 
- open a window to show all values of column M of W

    for iterations=1 to X
    <here some updates on values in W are made>
    {
     for i=1:M {
       for j=1:N {
           update value of W(i,j) in window j (without re-opening the window)
       }
    }

    }

我知道这样做的方法是使用plot函数,但即使在阅读官方文档后我也不太了解。

编辑 3 这是我现在拥有的代码

  [~:X] = size(W);   
   for i=1:X
    plot(W(:,i));
    end

有用。但是如何设置“仅打印点”?以及如何设置人物的位置(我的意思是,我希望人物不会出现在另一个之上?

的确切目标如下:假设 W 是一个 10*3 矩阵。

我想要3个数字。

在每个图中,应打印(并更新一定次数)列 i 中所有值的值。这些值应该打印为点(不像每个点都与其他点链接的函数)。

每个 POINT 代表一个元素 W(i,j)。更准确地说,该图应该是 ND SPACE 的二维空间中的表示,其中 N = W 的行数。

有什么进一步的建议吗?

4

3 回答 3

3

你正在尝试这个:

[~,X] = size(W);   
for i=1:X
    plot(W(:,i),[0:0.5:20],'none');
end  

这不起作用,因为每列W有 10 行,并且[0:.5:20]有 40 个元素。您需要具有匹配长度的向量才能使其起作用,而您不需要。

From your description, I think you might be looking for subplot, which has multiple sets of contained within a single "figure window":

figure;
[R,C] = size(W); 
for i=1:C
    subplot(C,1,i); #% creates axes for each column
    plot(W(:,i),1:R,'.k'); #% has appropriate x values
                #%   ^---- '.k' indicates unconnected dots (.), colored black (k)
end 

From the comments below, the question-asker is looking for a way to create figure windows so that each one contains a maximum of 4 subplots. There are many ways to do this; I've included one option below.

num_subplots = 4;
[R,C] = size(W); 
for i=1:C
    this_subplot_position = mod(i,num_subplots) + 1;
    if this_subplot_position == 1
        figure;
    end
    subplot(num_subplots,1,this_subplot_position); #% creates axes for each column
    plot(W(:,i),1:R,'.k'); #% has appropriate x values
                #%   ^---- '.k' indicates unconnected dots (.), colored black (k)
end 
于 2012-06-09T00:37:14.503 回答
1

通过窗口,我希望你的意思是数字。你能澄清一下吗?你有一个二维数组,你想在单独的图中逐列绘制该列?

figure(i);
plot(W(:,i),[0:0.5:20],linespecs); %to plot ith column on y axis, and x axis as ur [0:0.5:20]

对于更新,只需更改值,它应该相应地更改数字。

于 2012-06-08T22:12:48.403 回答
0

Matlab includes a command called refreshdata that makes problems like this a bit easier. In the example below we plot every column of W only once, but we set the YDataSource property so the plots automatically update when we later call refreshdata. The YDataSource property is a string containing a valid variable or command; here, it's W(:, 1) for the first plot, W(:, 2) for the second plot, etc.

for i_plot = 1:M
    subplot(M, 1, i_plot);
    plot(W(:, i_plot), '.', 'YDataSource', ['W(:, ' num2str(i_plot) ')']);
end

for i_plot = 1:M
    for i_point = 1:N
        W(i_point, i_plot) = rand;
        refreshdata;
        pause(0.1);
    end
end
于 2012-06-09T07:18:51.543 回答