フィルターのクリア

Using a while loop to call and name files.

1 回表示 (過去 30 日間)
Christopher Hall
Christopher Hall 2015 年 2 月 9 日
編集済み: Stephen23 2015 年 2 月 11 日
Hi,
I am trying to use a while loop to call files from a cell array. The cell array has one columns. Column 1 holds X,Y terrain data (512 x 2).
To manually get the data I have to use TD1 = TD{1,1}; however I am going to be dealing with possibly hundreds of rows of this data so need to be able to use a while loop.
The variable Num in this case is the total number of files which have been imported and the while function knows that it can stop once it as reached a value greater than it.
I want to store each variable from the while loop hence the ii value. So that I end up with TD1, TD2, TD3 ....
ii=1;
while ii <= Num
TD(ii) = TD{1,1};
|TD1 = TD{1,1};|
|TD2 = TD{1,2};|Current Manual Method
|TD3 = TD{1,3};|
end
  4 件のコメント
Stephen23
Stephen23 2015 年 2 月 9 日
編集済み: Stephen23 2015 年 2 月 11 日
Yes, exactly right, your example is perfectly correct. In every place where you want to use some variable, you can also refer to the indexed element of any cell array, structure, or any other kind of array. Instead of creating and referring to:
A1 = [A1 data]
A2 = [A2 data]
...
You should store your data together (here in a cell array):
A = {[A1 data],[A2 data]...};
Then refer to the elements of A:
A{1} % equivalent to your variable A1
A{2} % equivalent to your variable A2
...
For example:
min(A{1}) % min of the first element of the cell array, i.e. A1 data.
Go and try it! You will also find lots of helpful tools and functions that operate on your cell array , which will make your life a million times easier than if you named each variable individually.
Christopher Hall
Christopher Hall 2015 年 2 月 10 日
Many Thanks, This has sorted all my problems out.

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

採用された回答

Stephen23
Stephen23 2015 年 2 月 9 日

その他の回答 (1 件)

Sean de Wolski
Sean de Wolski 2015 年 2 月 9 日

カテゴリ

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