how to transfer a 3D variable into a row in an excel file?

1 vue (au cours des 30 derniers jours)
Elaheh
Elaheh le 9 Août 2020
Commenté : Image Analyst le 10 Août 2020
Hello all,
As shown in the attached document, I have "data"(EEG data) in the form of "numberOf_Electorrdes * numberOf_Points * rial" single variable.
How Can I write it in an excel file in one row (each row is one subject) and with as many columns as the number of electordes? I tired writetable(struct2table(EEG.data), 'data.xlsx' but I got this error "Input structure must be a scalar structure.
I have also the "lable of each electrode" and I need each number to go under the right channel.
EEGData= EEG.data;
ch_lables=EEG.chanlocs.labels; % I uesed this and only the first lable is shown?
I appreciate your help in advance.
Zahra
  3 commentaires
Elaheh
Elaheh le 9 Août 2020
The excel file was just used as an example. The number of channels is different for each person becuase
I delete channels that are too noisy. so the number differs. In this example file, the size is :
size(EEGData)
ans =
62 75 14
> class(EEGData)
ans =
'single'
dpb
dpb le 9 Août 2020
Need clarification on what you're asking to do -- the 3D array is nElectrodes X nPoints x nTrials for some observation?
What do you want out of this 3D array to go where into an output record that is a vector observation? For
data(1:nElectrodes,j,k)
one would have nElectrodes observations of the j,k-th observation; there would then be nPoints*nTrials rows to output the full data array -- and one would have to pick the order in which to iterate over j,k to know in which order the data were stored...one would also need to save what those two dimensions were to avoid potentially ambigous interpretation of using said data.
As always, showing an actual example of possible input and expected output with illustration of how the result follows from the input would make things much more clear.

Connectez-vous pour commenter.

Réponse acceptée

Image Analyst
Image Analyst le 9 Août 2020
In general, you can make a row vector out of your 3-D variable like this:
rowVector = array3d(:)';
% Now write to Excel
xlswrite(filename, rowVector, sheetName, 'A1');
array3d(:) turns it into a column vector, and then the apostrophe transposes it into a row vector.
  2 commentaires
Elaheh
Elaheh le 10 Août 2020
Thank you for your response. I got this error :
The specified data range is invalid or too large to write to the specified file
format. Try writing to an XLSX file and use Excel A1 notation for the range
argument, for example, ‘A1:D4’.
Image Analyst
Image Analyst le 10 Août 2020
Elaheh, this script works just fine for me:
fprintf('Beginning to run %s.m ...\n', mfilename);
array3d = randi(255, 2, 4, 2) % Create 3-D matrix.
rowVector = array3d(:)'
sheetName = 'Results';
% Now write to Excel
fileName = 'deleteme.xlsx';
xlswrite(fileName, rowVector, sheetName, 'A1');
if ispc
winopen(fileName)
end
fprintf('Done running %s.m ...\n', mfilename);
Perhaps your 3-D array is so huge it can't fit on one row in Excel. What does this say:
size(yourArray)
numel(yourArray)

Connectez-vous pour commenter.

Plus de réponses (1)

Sulaymon Eshkabilov
Sulaymon Eshkabilov le 9 Août 2020
Hi,
a simple solution might be this one:
for ii=1:14 % EEGData has 14 layers
SH=strcat('Sheet', num2str(ii));
xlswrite('EEGData_ALL.xlsx', EEGData(:,:,ii), SH); % Note that you will have 14 seprate sheets of data
end
  2 commentaires
Elaheh
Elaheh le 10 Août 2020
Thank you so much.
It worked.
Image Analyst
Image Analyst le 10 Août 2020
How does it work? It does not write your entire 3-D array out to a single row in Excel as you asked.

Connectez-vous pour commenter.

Produits


Version

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by