How can I break down a data matrix of say 1024x961 to 961 single files of 1024x1 matrix with filenames corresponding to the column number?
Show older comments
No programming experience before, generally use matlab for plotting figures. ask for several lines of code that can help me break down this data file into pieces (save them as -mat, -txt, or -ascii) so that I could proceed processing the data. Any help will be much appreciated!
e.g. spectrum_001=originalfile(:,1); spectrum_961=originalfile(:,961)
Accepted Answer
More Answers (1)
Image Analyst
on 2 Mar 2014
Hao: Azzi's code should have done it. Perhaps you just need to have it use the same names you picked and to be a little more explicit in the steps, like I show in the code below:
filebrowser; % Make sure Current Folder panel is showing.
% Create sample data for this demo
originalfile = rand(1024,3);
% Define the folder where you want to save all the files.
folder = pwd; % Whatever folder you want
% Loop across all the columns, saving each one to its own file.
for column = 1 : size(originalfile, 2)
thisColumn = originalfile(:, column);
baseFileName = sprintf('spectrum_%3.3d.mat', column);
fullFileName = fullfile(folder, baseFileName);
save(fullFileName, 'thisColumn') % save to mat file
end
Categories
Find more on Data Import and Management 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!