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

조회 수: 2 (최근 30일)
Folakemi Omotoye
Folakemi Omotoye 2018년 7월 31일
댓글: Image Analyst 2018년 7월 31일
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

답변 (1개)

Image Analyst
Image Analyst 2018년 7월 31일
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
Folakemi Omotoye
Folakemi Omotoye 2018년 7월 31일
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 2018년 7월 31일
OK, well . . . good luck with it.

댓글을 달려면 로그인하십시오.

Community Treasure Hunt

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

Start Hunting!

Translated by