using loops to assign numerically assigned variables?

2 ビュー (過去 30 日間)
Samuel
Samuel 2013 年 1 月 29 日
Hello all. Sorry for the confusing question subject line, but I felt it best outlined it.
I know that I can assign variables to text files that are in numerical order, such as file1.txt, file2.txt, etc can be assigned to variables automatically by using a line such as
file=['file' num2str(wfm) '.txt'];
Then can I do a similar thing if have variables that have been assigned in succession of numbers in a loop instead of assigning each one, and also to assign the first few elements of them? Such as: Instead of
b1=14+value1(1:40)
b2=14+value2(1:40)
b3=14+value3(1:40)
How would i code it so it does for i=1:3 ['b' num2str(i)]=14+['value' num2str(i)](1:40); end
By the way, I am asking for this method because in my application, value1,value2,and value3 are of different lengths and therefore a simple assignment of variables to one variable with an index won't work.
Thanks in advance for your help.
Sam
  3 件のコメント
Samuel
Samuel 2013 年 1 月 29 日
haha I just wrote a sample pseudocode to outline my issue. My actual code involves 10 of those (and more to come as I process more tests), and noticed that there must be an easier way involving indexed arrays and for loops to accomplish the task.
Image Analyst
Image Analyst 2013 年 1 月 29 日
So use a 2D array, or a cell array.

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

採用された回答

Sean de Wolski
Sean de Wolski 2013 年 1 月 29 日
  1 件のコメント
Samuel
Samuel 2013 年 1 月 29 日
Reading the guide I think using cell arrays will enable me to assign a sequence of arrays of different dimensions. I will accept this answer and will follow up the thread if I run into problems. Thanks!

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

その他の回答 (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