how to loop through matrix?

I have a 184x32 matrix, I would like to write a loop to print out the first 8 rows then skip the next 8 rows. for example
  • A
  • B
  • C
  • D
  • E
  • F
  • G
  • Houtcome should print A-H and skip I-O and print from P-X till the end .

2 件のコメント

Azzi Abdelmalek
Azzi Abdelmalek 2014 年 1 月 14 日
You said till the end, what is the end in your case. And what is your array? a cell array? or what?
andrew
andrew 2014 年 1 月 15 日
it is a cell array and end I mean the entire matrix

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

回答 (1 件)

Image Analyst
Image Analyst 2014 年 1 月 14 日

0 投票

One of many many ways to do this:
m = randi(9, 184, 32)
[rows, columns] = size(m);
for row = 1 : 16 : rows
fprintf('\nRows %d - %d\n', row, row+7);
fprintf('%d, ', m(row,:));
fprintf('\n');
fprintf('%d, ', m(row+1,:));
fprintf('\n');
fprintf('%d, ', m(row+2,:));
fprintf('\n');
fprintf('%d, ', m(row+3,:));
fprintf('\n');
fprintf('%d, ', m(row+4,:));
fprintf('\n');
fprintf('%d, ', m(row+5,:));
fprintf('\n');
fprintf('%d, ', m(row+6,:));
fprintf('\n');
fprintf('%d, ', m(row+7,:));
end

カテゴリ

ヘルプ センター および File ExchangeCreating and Concatenating Matrices についてさらに検索

タグ

質問済み:

2014 年 1 月 14 日

コメント済み:

2014 年 1 月 15 日

Community Treasure Hunt

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

Start Hunting!

Translated by