【发布时间】:2012-04-16 02:02:38
【问题描述】:
您好,我正在尝试找到一种方法在 MatLab 中创建一个矩阵,其中仅包含在 30 秒内重复的练习的最大值和最小值。
例如,如果我有数据集:
data = [1 3 5 7 9 6 4 2 3 6 8 10 7 6 4 2 1]
我想要的结果是:
output = [1 9 2 10 1]
该函数只会绘制不断变化的波形的峰值。
我试过的代码如下:
size = length(data); %Get the length of the dataset
x = 1; %Set a counter value
maxplot = 0; %Default, a maximum value has not yet been plotted
for x = 1:size-1
a1 = data(1,x); %Get two adjacent samples of the dataset
a2 = data(1,x+1);
v = 1; %Set the initial column for the max points matrix
while maxplot == 0
if a1 > a2
max(v,1) = a1;
v = v + 1;
maxplot = 1;
end
end
if a1 < a2
maxplot = 0;
end
end
感谢提前回复的人,
贾里德。
【问题讨论】:
-
你有没有试过写一个这样的函数?看起来没那么难……
-
我已经尝试过,但我是使用 MatLab 的新手。我想我不小心创建了一个无限循环,因为 MatLab 卡在“忙碌”状态
-
您可以发布您尝试过的内容,然后有人可以帮助您...
-
是的,如果
a1 <= a2... 看起来像 someone has written a function that does this,则您的 while 外观永远不会退出。
标签: matlab max data-analysis