필터 지우기
필터 지우기

Using a for- loop to extract a range of columns every n-columns

조회 수: 3 (최근 30일)
Carlos_conde
Carlos_conde 2022년 6월 29일
댓글: Carlos_conde 2022년 6월 30일
Hi all,
I have a 64x10000 matrix. Now I am trying to select certain columns within.
I want to select 200 columns every 2000 columns, so at the end my data would be a matrix of size 64x1000
Right now, my code looks like this :
data = rand(64,10000);
for w=1:5
extract_data(w)=data(:, (2000*(w-1))+1:200)
end
I hope that you can help me,
Thanks,

채택된 답변

Walter Roberson
Walter Roberson 2022년 6월 29일
data = rand(64,10000);
startcols = 1:2000:size(data,2)-1999;
for w = 1:length(startcols)
sc = startcols(w);
extract_data(:,200*(w-1)+1:200*w)=data(:, sc:sc+199);
end
size(extract_data)
ans = 1×2
64 1000
  댓글 수: 2
Carlos_conde
Carlos_conde 2022년 6월 29일
thanks a lot
Walter Roberson, you are a lenged!
Carlos_conde
Carlos_conde 2022년 6월 30일
I was trying to understand your code again, and I think that I do not catch the reason for -1999
Can you please explain that?

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Whos에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by