Filter löschen
Filter löschen

How can i convert a vector (1 by 300) into time points

1 Ansicht (letzte 30 Tage)
Folakemi Omotoye
Folakemi Omotoye am 31 Jul. 2018
Kommentiert: Image Analyst am 31 Jul. 2018
I have a 1 by 300 vector. I want to convert it to time points and write a program such that the system will read the cumulative sum from the first point to the current point and output a value if the sum is higher than a specified threshold. If not higher, it will continue to add up the values at the time points. i have written some code below but it is not giving me what I want.
time=1:300;
[vector]=v(t)
for time=1:300
if [v(t)] < 0; Then
[v]= 0; % set the value of threshold
end
if v(t) + v(t+1) >= 1; Then
[v]= 4; % set the value of the threshold
% note the time of increment
end
end

Antworten (1)

Image Analyst
Image Analyst am 31 Jul. 2018
Lots of errors.
  1. Don't use time as a variable name because it's a built-in function.
  2. Don't use square brackets like you have done.
  3. You need to define t and v.
  4. Make sure that t+1 never exceeds the length of v.
  5. Setting v to a scalar of 4 will cause the next iteration to bomb because you're trying to access the t'th element of an array, and it's no longer an array - it's a scalar.
  6. No need to use a semicolon at the end of an if statement.
  7. You can't use Then - this is MATLAB, not Visual Basic.
  8. You declare vector but never use it.
etc. Make another shot at it after those corrections are made and we'll try again.
  2 Kommentare
Folakemi Omotoye
Folakemi Omotoye am 31 Jul. 2018
thanks for the correction. i have done the corrections but my output is not what i want. v is the 1x300 vector t is the time
Image Analyst
Image Analyst am 31 Jul. 2018
OK, well . . . good luck with it.

Melden Sie sich an, um zu kommentieren.

Community Treasure Hunt

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

Start Hunting!

Translated by