Unidentified function or variable in Matlab cannot figure out

I'm trying to write a for loop with a counter. The counter starts at 1 and goes up to 5000. I want the function to use all the numbers up to 5000. This is what I have so far.
j = 1;
for i = 1:length(RT)
if RT(i) < 5000 ;
newRT(j) = RT(i);
j = j+1;
end
end
Is there something wrong with my code? Matlab will not display anything. It is saying the variable RT is undefined.

3 件のコメント

per isakson
per isakson 2012 年 9 月 22 日
Nothing in your code indicates that RT is defined!
Josh
Josh 2012 年 9 月 22 日
if RT were defined as an array of data, would the code work?
As in RT is an array of data and all i want is the data whose values are less than 5000.
Josh
Josh 2012 年 9 月 22 日
Thank you!

サインインしてコメントする。

回答 (1 件)

per isakson
per isakson 2012 年 9 月 22 日
編集済み: per isakson 2012 年 9 月 22 日

0 投票

Yes, I cannot see any problem. This code
RT = 1e4 * rand( 1, 100 );
jj = 1;
for ii = 1:length(RT)
if RT(ii) < 5000 ;
newRT(jj) = RT(ii);
jj = jj+1;
end
end
whos newRT
produce this output
Name Size Bytes Class Attributes
newRT 1x56 448 double

カテゴリ

ヘルプ センター および File ExchangeLoops and Conditional Statements についてさらに検索

質問済み:

2012 年 9 月 22 日

Community Treasure Hunt

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

Start Hunting!

Translated by