Calculating an average if specific condition is fulfilled

13 次查看(过去 30 天)
Hello everybody,
I am working on my own project right now and needing some help now.
What do I want to do?
Matlab should calculate the average out of values for a specific time period.
time (sec) value
0 2
1 3
2 4
3 6
4 7
5 8
6 2
If time is >0 and smaller or equal to 3 sec Matlab should calculate the arithmetic average of the values.
So basically something like this:
IF 0>=time>=3
Do arithmetic average of value
So the result should be (2+3+4+6 )/4 =3,75.
It is my first project with MatLab and I am usually working with other programms.
Thanks for your help.
Your sincerely,
Max

回答(1 个)

madhan ravi
madhan ravi 2019-5-6
编辑:madhan ravi 2019-5-6
https://in.mathworks.com/company/newsletters/articles/matrix-indexing-in-matlab.html - read the topic logical indexing once you understand that use mean() after that process.
I also suggest you to do MATLAB on-ramp course.
  6 个评论
Max Behr
Max Behr 2019-5-7
I have one more question...
What should I do if the amout of values are NOT the same?
time1= 1 2 3 END
time 2 = 1 2 3 4 5 END
values1= 4 5 6 END
values2 1 2 4 5 6 END
Should I still put them into one matrix?

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

产品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by