Using a For Loop with the variable set to a series defined matrix values?

Hi. I have a program where I'm trying to implement a range of values that the user can examine, between 1 and 64. I want to run the program and have it cumulatively plot the results at all predefined window sizes.
I keep trying something like this, using all kinds of different combinations of brackets (I'm new to programming and MATLAB):
for window = ([1:64], [30:31], [21:29], [etc])
windowval = window % Used to test the For loop in the practice/test program
end
Usually windowval ends up equaling 1, then 2, then 3, etc. I want it to equal 1:64, as in, [1 2 3 4 5 6 ... 64], then on the next iteration, [30:31], etc.
Any tips? When I use doc for, the closest thing to what I want is just for a defined set of index values, s = [3,5,8,10]...
EDIT: Also, I should say, I want the user to be able to easily be able to implement these ranges into the script directly (but manually).

 採用された回答

Thorsten
Thorsten 2015 年 5 月 21 日
編集済み: Thorsten 2015 年 5 月 21 日
Have you tried this combination of brackets? ;-)
for window = {1:64, 30:31, 21:29}
windowval = cell2mat(window);
end

2 件のコメント

Jan
Jan 2015 年 5 月 21 日
編集済み: Jan 2015 年 5 月 21 日
Or faster:
windowval = window{1};
Alexander Ross
Alexander Ross 2015 年 5 月 21 日
編集済み: Alexander Ross 2015 年 5 月 21 日
Thank you both, this worked very nicely! I feel like a fool for not being able to figure it out! Have a great day!

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

その他の回答 (1 件)

Jan
Jan 2015 年 5 月 21 日
編集済み: Jan 2015 年 5 月 21 日
ini = [1, 30, 21];
fin = [64, 31, 29];
for iWindow = 1:numel(ini)
WindowVal = ini(iWindow):fin(iWindow);
end

カテゴリ

ヘルプ センター および File ExchangeMatrix Indexing についてさらに検索

製品

質問済み:

2015 年 5 月 21 日

編集済み:

2015 年 5 月 21 日

Community Treasure Hunt

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

Start Hunting!

Translated by