Read and writing matrices; need to keep column labels??

10 views (last 30 days)
Hi, I am altering data sets by reading in .tsv files, performing operations and then wrting them out to .xlsx
The problem I am having is that while all of the numerical data saves/writes to the file I am losing the column names. Is there an easy way to do this?
Here is the code I am using:
% load data set in via user:
prompt = 'please enter file: ';
filename = input(prompt, 's');
eeg = readmatrix(filename);
[r c] = size(eeg);
waved_delta = eeg;
% delta [1 - 4 Hz],
% theta [4 - 8 Hz],
% alpha [8 - 12 Hz],
% beta [12 - 35 Hz],
% gamma [35 - 45 Hz]
for i = 1:c
[in f] = cwt (eeg (:,i),'amor',500);
waved_delta (:,i) = (icwt (in ,f,[1 4]))';
% so that I can feel like it's really doing something
fprintf('completed iteration: %d\n', i)
end
% this command is being done in the inline command not the script above
% because I am saving different file names
writematrix(waved_delta, new.xlsx');
When I open my .tsv files using excel I get my channel labels (column A is Time, B is Ch1, etc.) but when I write these files out they don't have the labels.
Am I missing a step?
Thanks for any help!

Answers (1)

Walter Roberson
Walter Roberson on 17 Oct 2020
% load data set in via user:
prompt = 'please enter file: ';
filename = input(prompt, 's');
eeg = readtable(filename);
[r, c] = size(eeg);
waved_delta = zeros(r,c);
% delta [1 - 4 Hz],
% theta [4 - 8 Hz],
% alpha [8 - 12 Hz],
% beta [12 - 35 Hz],
% gamma [35 - 45 Hz]
for i = 1:c
[in, f] = cwt(eeg{,i}, 'amor', 500);
waved_delta(:,i) = icwt(in ,f,[1 4]);
% so that I can feel like it's really doing something
fprintf('completed iteration: %d\n', i)
end
% this command is being done in the inline command not the script above
% because I am saving different file names
waved_delta = array2table(waved_delta, 'VariableNames', eeg.Properties.VariableNames);
writetable(waved_delta, 'new.xlsx');

Categories

Find more on EEG/MEG/ECoG 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!