split column vector into sub-columns and rename
조회 수: 1 (최근 30일)
이전 댓글 표시
i have 24360 rows by 1 column vector and i want to split or chop it into 1015 rows by 1 column vector and save them (that would give me 24 of the 1015x1 vector ) which i would either live to save separately as single 1015by1 column vectors or single 1015by24 file
ideally i would want the output to look like the output of the code below
mat=zeros(24,1015)
for k=1:24
vec=[3:1017]+k
mat(k,:)=vec
end
mat;
dlmwrite('mat.txt',mat,'delimiter',' ');
% similar to the above structure this is what i wrote :
load 'random24at31050.txt'; % input file google drive link is :
% https://drive.google.com/a/columbia.edu/file/d/0B_AwZrt6f2FzUS1nUWQzZEhVZFE/view?usp=sharing
intensity= random24at31050(:,4);% copy 4th column of input file ,this single column has 24360 rows
collect_ramanintensity=zeros(1015,24)
for k =1:24
ramanintensity=intensity((k*1015-(k*1015)+1):k*1015,:);
collect_ramanintensity(1:length(ramanintensity),k)=ramanintensity% collect_ramanintensity(:,k) isnt working
end
collect_ramanintensity;
dlmwrite('collect_ramanintensity.txt',collect_ramanintensity,'delimiter',' ');
This is not coming out as the 1015by24 matrix I expected I would appreciate any suggestions ....I am open to
댓글 수: 2
bitslice
2015년 8월 2일
Hey, have you tried the reshape function?
% Assuming vec is your 24360 x 1 vector
reshape(vec, 1015, 24)
채택된 답변
Nick Hobbs
2015년 8월 4일
Building on the previous comment, the reshape function would be able to convert your vector to the specified format. To get an idea on how 24360x1 vector will be reorganized, the documentation for reshape includes a few examples. However, the command
newMatrix = reshape(givenVector, [1015, 24])
will reshape your new matrix for you.
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!