Hello, I am trying to extract every 2000 rows in a 20000 row column and place each extracted matrix into a separate column to create a 2000x10 matrix. However, I am getting an error: In an assignment A(:) = B, the number of elements in A and B must be the same. Any ideas?
Test=zeros(2000,10);
for w=1:10
Test(w)=zt3((2000.*(w-1))+1:2000.*w,1:1)
end

 채택된 답변

OCDER
OCDER 2017년 9월 19일
편집: OCDER 2017년 9월 19일

0 개 추천

Is this what you want to do?
zt3 = [1:20000]'; %assuming zt3 is a 20000x1 matrix
Test = reshape(zt3, 2000, 10);
%Takes row 1:2000, 2001:4000, etc and stores each in a column in a new matrix.

댓글 수: 4

Francis Herman
Francis Herman 2017년 9월 19일
Not exactly. I would like to take all values in each 2000 row intervals and place them into a new matrix. So rows 1-> 2000 goes into the first column of the new matrix; rows 2001->4000 goes into the second column of the new matrix; etc.
OCDER
OCDER 2017년 9월 19일
Oh, I see. For this case, maybe reshape is the better option, assuming dzt is a 20000x1 matrix. I changed the answer above.
Francis Herman
Francis Herman 2017년 9월 19일
Yes, this solved my problem. Thank you very much for the help.
OCDER
OCDER 2017년 9월 19일
You're welcome! Oh, I should have explained why your code didn't work. You were doing Test(w) = zt3(1:2000), but Test(w) is 1 element while zt3(1:2000) is 2000 elements. The elements must match in input and output. To make the for loop work, you'd have to fix it as below:
Test = zeros(2000, 10);
for w = 1:10
Test(:, w) = zt3(2000*(w-1)+1:2000*w, 1);
%Fill all row " : " for column number w in Test
end

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

추가 답변 (1개)

Walter Roberson
Walter Roberson 2017년 9월 19일

0 개 추천

T = mat2cell(zt3, 2000*ones(1,size(zt3,1)/2000), size(zt3,2));

카테고리

도움말 센터File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

태그

질문:

2017년 9월 19일

답변:

2017년 9월 19일

Community Treasure Hunt

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

Start Hunting!

Translated by