How to select rows in a matrix with a for loop?

I have a 3061x107 matrix. I want to reduce it to a 817x107 matrix. My current code currently saves what I want as a new matrix into a very large column so its 87000x1.
My current code:
density=[];
for i=1:length(densityt)
dcol=densityt(:,i);
dcol=dcol(1:817,:);
density=[density;dcol];
end

回答 (1 件)

Ameer Hamza
Ameer Hamza 2020 年 12 月 13 日

0 投票

Following code is more efficient and outputs what you want
density = densityt(1:817, :)

カテゴリ

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

質問済み:

2020 年 12 月 13 日

回答済み:

2020 年 12 月 13 日

Community Treasure Hunt

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

Start Hunting!

Translated by