简体   繁体   English

Matlab bar3情节

[英]Matlab bar3 plot

I have a problem with MATLAB bar3 plots: Here is what I have: 我对MATLAB bar3图有问题:这就是我所拥有的:


m x n Array Values containing values of a measurement. m×n阵列Values含有一个测量的值。

Another m x n Array Angles Represents the angle at which a value was measured (eg the 3rd value was measured at an angle of 90°). 另一个m × n阵列Angles表示测量值的角度(例如,第三个值是以90°的角度测量的)。 The angular values for each measurement value are stored in another variable. 每个测量值的角度值存储在另一个变量中。


I need a range for my x-axis from -180° to +180°. 我需要一个从-180°到+ 180°的x轴范围。 This alone is no problem. 仅此一点是没问题的。 But how do I hand over my measurement values? 但是,我如何交出我的测量值? I have to somehow link them to the angular values. 我必须以某种方式将它们链接到角度值。 So that each value in Values is somehow linked to it's angular value in Angles . 因此,在每个值Values以某种方式链接到它的角度值Angles For my y-axis, I can simply count from 0 to the amount of rows of my Values Array. 对于我的y轴,我可以简单地从0计算到我的Values Array的行数。

EXAMPLE: 例:

Values looks like: Values看起来像:

3   5   6
2   1   7
5   8   2

Angles looks like: Angles看起来像:

37°   38°   39°
36°   37°   38°
34°   35°   36°

Values(1,1) = 3 was measured at Angles(1,1) = 37° for example. 例如,在Angles(1,1) = 37°测量Values(1,1) = 3

At each angle, the number of bars varies depending on how many measurements exist for that angle. 在每个角度,条的数量取决于该角度存在多少测量值。 bar3 needs a matrix input. bar3需要一个矩阵输入。 In order to build a matrix, missing values are filled with NaN . 为了构建矩阵,缺少的值用NaN填充。

Warning: NaN s are usually ignored by plotting commands, but bar3 apparently breaks this convention. 警告:绘制命令通常会忽略NaN ,但是bar3显然违反了这个约定。 It seems to replace NaN s by zeros! 它似乎用零替换NaN So at missing values you'll get a zero-height bar (instead of no bar at all) . 因此,在缺失值时,您将获得零高度条(而不是根本没有条)

[uAngles, ~, uAngleLabels] = unique(Angles); %// get unique values and
    %// corresponding labels
valuesPerAngle = accumarray(uAngleLabels(:), Values(:), [], @(v) {v});
    %// cell array where each cell contains all values corresponding to an angle
N = max(cellfun(@numel, valuesPerAngle));
valuesPerAngle = cellfun(@(c) {[c; NaN(N-numel(c),1)]}, valuesPerAngle);
    %// fill with NaNs to make all cells of equal lenght, so that they can be
    %// concatenated into a matrix  
valuesPerAngle = cat(2, valuesPerAngle{:}); %// matrix of values for each angle,
    %// filled with NaNs where needed
bar3(uAngles, valuesPerAngle.'); %'// finally, the matrix can be plotted
ylabel('Angles')
xlabel('Measurement')

With your example Values and Angles this gives: 使用您的示例ValuesAngles这给出:

在此输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM