【问题标题】:Matlab - Cumulative Distribution of trajectoryMatlab - 轨迹的累积分布
【发布时间】:2023-04-05 08:14:01
【问题描述】:

据我所知,我在任何地方都没有找到任何答案来解决我的问题。我认为自己在 Matlab 中相当不错。

我记录了肿瘤的轨迹与时间的关系like on this image。我想计算累积分布,以显示肿瘤从理想位置 x=0 like on this picture generated with another software 的时间与位移。

累积图的意思是我们可以找到肿瘤在采集过程中在某个位置之外花费的总时间。您会看到肿瘤在位置 0 的位置是整个采集时间的长度(~300 秒)。如果我们正在寻找肿瘤在距离理想位置 1.1 毫米之外停留的时间,它将表示~100 秒.肿瘤在2.8mm之外的时间变得非常接近0s。

任何可以帮助我获得这样的代码都会很棒。我强烈感觉到与 cumsum、cdf 等有关,但我真的没有设法找到合适的功能。我的下一个选择是自己装箱并为其编写代码。

感谢您的帮助。

【问题讨论】:

    标签: matlab function histogram distribution motion


    【解决方案1】:

    您可以使用hist(x) 找到发行版。然后通过向后计算cumsum()就可以画出想要的情节了。

    clc, clear all, close all
    seconds = 303;              % Amount of time that passed during the test
    datapoints = 3000;          % Amount of Datapoints in your vector 
    
    x = randn(datapoints,1);
    [counts,centers] = hist(abs(x),sort([0;unique(abs(x))]));
    
    sumX = sum(counts);
    cumsumX = cumsum(counts);
    time = (sumX - [0 cumsumX(1:end-1)])*seconds/datapoints; % Normalize result with factor
    
    figure
    plot(centers, time)
    

    【讨论】:

    • 嗨 Dennis Klopfer,这绝对可以帮助我实现我的目标。但是,我希望能够在最后以时间作为 y 坐标来绘制情节。如果我们有位置与时间的轨迹,如以下代码:x = randn(3000,1); time = cumsum(ones(3000,1));,那么绘制plot(centers, time 的最佳方式是什么?谢谢,文森特
    • 我已经更新了我的答案。如果这回答了您的问题,如果您接受答案,我会很高兴。如果您有更多问题,请告诉我。
    • 太棒了 :) 非常感谢!
    猜你喜欢
    • 1970-01-01
    • 2012-06-08
    • 1970-01-01
    • 2018-05-22
    • 2014-05-30
    • 1970-01-01
    • 2016-05-27
    • 2013-03-02
    • 1970-01-01
    相关资源
    最近更新 更多