split column vector into sub-columns and rename
1 view (last 30 days)
Show older comments
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 Comments
bitslice
on 2 Aug 2015
Hey, have you tried the reshape function?
% Assuming vec is your 24360 x 1 vector
reshape(vec, 1015, 24)
Accepted Answer
Nick Hobbs
on 4 Aug 2015
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 Comments
More Answers (0)
See Also
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!