Searching Loop issues , not saving to cell array

2 ビュー (過去 30 日間)
Christopher Hall
Christopher Hall 2015 年 5 月 9 日
編集済み: Christopher Hall 2015 年 5 月 9 日
Hi,
I am trying to scan through x,y data to find values which lie within a certain x,y range. I cannot however get the data to save to the cell arrays. When I enter the nnn value individually I get the correct result and it saves to the cell array. However when I run it in loop the data does not save to the array and it just gives me an array of [2000,1] all empty.
Is there something I am missing?
The x values I am scanning are from -1000 to 1000
y values are as a function of y(n,1) = H*exp(-(j/k)*log(2));
x100 = (-1000:1000)';
y100 = y + 100;
for nnn = (1:2001)
yrange = y100(nnn,1);
yrangemin= yrange -5;
yrangemax= yrange +5;
xrange = x100(nnn,1);
xrangemin = xrange - 5;
xrangemax = xrange + 5;
searchx = find((pointsx)>xrangemin & (pointsx)<xrangemax);
searchy = find( pointsy>yrangemin & pointsy<yrangemax);
ANS = {};
ANS{nnn,1} = searchx;
ANS{nnn,2} = searchy;
if samplesize > 1000;
end
end
end
  2 件のコメント
Walter Roberson
Walter Roberson 2015 年 5 月 9 日
I reformatted for readability, but you seem to have introduced a stray "end", possibly while using the "Code" button to insert the code.
Christopher Hall
Christopher Hall 2015 年 5 月 9 日
編集済み: Christopher Hall 2015 年 5 月 9 日
Many Thanks, I will try and be more careful when using the code button in the future.

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

採用された回答

Walter Roberson
Walter Roberson 2015 年 5 月 9 日
Remove your statement
ANS = {};
from inside your "for" loop.
  1 件のコメント
Christopher Hall
Christopher Hall 2015 年 5 月 9 日
Haha im such an idiot... thanks Walter!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by