extracting particular row and column

20 ビュー (過去 30 日間)
Tanmoyee Bhattacharya
Tanmoyee Bhattacharya 2016 年 5 月 3 日
I have a matrix like this
1 2 3 4
1 2 3 4
1 2 3 4
1 2 3 4
5 6 7 8
5 6 7 8
5 6 7 8
5 6 7 8
9 10 11 12
9 10 11 12
9 10 11 12
9 10 11 12
like that so many rows.I want to extract every 4 row and 4 column continuously for whole row and save it in excel file.For a single row it works b=a(1:1:4),:);but for all row how can it possible.

採用された回答

Guillaume
Guillaume 2016 年 5 月 3 日
Do you mean?
b = a(1:4:end, :)
  5 件のコメント
Guillaume
Guillaume 2016 年 5 月 3 日
編集済み: Guillaume 2016 年 5 月 3 日
I believe this is what you want:
assert(mod(size(a, 1), 4) == 0, 'number of rows is not a multiple of 4');
numcells = size(a, 1) / 4; %number of matrices generated
b = mat2cell(a, ones(1, numcells)*4, size(a, 2)); %split a into matrices
%save as excel file however you want, e.g.:
savepath = 'C:\wherever\you want\to save your files\');
for bidx = 1:numcells
xlswrite(fullfile(savepath, sprintf('%4d.xlsx', bidx)), b{bidx});
end
Tanmoyee Bhattacharya
Tanmoyee Bhattacharya 2016 年 5 月 4 日
Sir it is really fantastic.It works.

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

その他の回答 (1 件)

Image Analyst
Image Analyst 2016 年 5 月 3 日
Guillaume's first answer gave you every 4th row extracted from the original, and all columns will be included. Perhaps when you say you "want to extract every 4 row and 4 column" you want this:
m4 = m(1:4:end, 1:4:end);
or
m4 = imresize(m, 0.25, 'nearest');
This will subsample the matrix by 4 in both the row and column direction.

カテゴリ

Help Center および File ExchangeStandard File Formats についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by