Can someone help me solve this problem (Array indices must be positive integers or logical values)

I tried to get the answer from this equation: sum(abs(diff(CPap)))*freq/length(CPap)
I assumed I need to tell matlab what CPap, freq and length represent right?
So I typed in CPap = 0.3, freq = 100 an length = 10
But when i hit enter, this sentence showed, can someone tell me what am i doing wrong here?
Many thanks!!!

Answers (1)

The issue is with length(CPap). You're trying to divide sum(abs(diff(CPap)))*freq by length(0.3), in your case length is not an array. If it was an array, then indices must be positive integers

7 Comments

Thanks so much for the reply. Sorry I don't quite follow, does this mean the order of my equation is wrong? or what do I have to change?
Naming a variable length is not a good idea MATLAB has an in-built function named length().
As Madhan said length() is a built-in function, it returns the largest array dimension of the input argument.
It is not clear to me on what you are trying to do here. Is CPap an array? Is length a variable or are you trying to find the length of CPap?
I tried labelling x or lengthh but this came up too.
Index exceeds the number of array elements (1).
Also, am I differenciating a constant number here? Casue no matter what I do I will get 0 at the end? sum(abs(diff(CPap)))*freq/length(CPap)
So what I try to find is the Centre of pressure mean velocity (CPmVel), and this is the equation I found in published research article: MVap=sum(abs(diff(CPap)))*freq/length(CPap)
Now I got the value of Centre of pressure in Anterio-posterior direction (CPap) 30mm, frequency of 100Hz and length or duration of 10s. I just want to use the above equation and find MVap via Matlab. It's my first time using Matlab too so sorry if what I'm asking is too elementary...
Really apprecitaed you guys helping out!
Let's say x is an array.
x = [9 7 5 3 2]
x(1) = 9, x(2) = 7, ... , x(5) = 2
What you're trying to do is x(Cpap), which is equivalent to x(0.3). 0.3 is not a valid array index. Array indexes can only be positive and integer values.
Index exceeds the number of array elements (1)
This happens when you call for x(6) because, x(6) is not defined.
Also, am I differenciating a constant number here? Casue no matter what I do I will get 0 at the end?
Yes, diffrentiating on a constant will return zero but, the function diff() has other uses as well. I encourage you to read the documentation.
It'll be helpful if you explain what you're trying to achieve. Use to latex editor to type in the equation or post a screenshot of the equation you're trying to implement.
This is the equation I found in published research article:I try to find the mean velocity
Mean Velocity in AP direction =sum(abs(diff(CPap)))*freq/length(CPap)
This is my research dissertation and I 'll try to explain what I'm trying to find here, please bare with me if it gets too boring:
Basically I put participants on a forceplate with a series of standing tasks and measure their centre of pressure in ax and ay direction in 10 seconds (Anterio-posterior and Medio-lateral direction, as shown in graph). This is known as postural sway (how much sway we have during those tasks). Now within the COP, there are other parameters that can be calculated like the mean velocity (the one I'm trying to calculate). I got a column of data numbers (COP) within that 10 seconds duration so I calculated the average of each direction (AP and ML) and came up with two numbers. And I think COP is a vector, so am I doing it wrong by caculating the average from all data?fp_type6.jpg

Sign in to comment.

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Products

Asked:

on 28 Mar 2019

Commented:

on 28 Mar 2019

Community Treasure Hunt

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

Start Hunting!