Dear all,
I'm pasting all code to let you find all mistakes I made. The error is located in line with fprintf in the end. Mr MATLAB says:
*Error using fprintf Function is not defined for 'cell' inputs.
Error in setcolours (line 57) fprintf(fileID,formatSpec,colours{ch,:});*
I read many answers to similar questions but none of them helped me. I need to save these rows of strings for every channel (more or less 250 strings for 22/32/64 channels) in such way that Unity could read this then, recommended solution is array in .txt file. How can I rich my goal?
I can't attach .edf file, if there is a need, I doubt, you can find them there http://physionet.org/cgi-bin/atm/ATM in EEG Motor Movement Dataset.
Code:
function [colours] = setcolours()%Function determines ranges of values that channels recorded at given time.
%edfread and data from physionet were used.
%Saved .txt file will be read by Unity to represent ranges of recorded values
%in brain model in Virtual Reality.
%Authors: M. Chen, V. Colaco, K. Wieciorek
%read .edf file (ask user for name of file (input)
rec = input('Type name of the record to be analysed, remember about .edf extension and '' '); [hdr, record] = edfread(rec);%Reads data from ALL RECORDS of file fname ('*.edf'). Header information is returned in structure hdr,
%and the signals (waveforms) are returned in structure record, with waveforms associated with the records
%returned as fields titled 'data' of structure record.
[nrows, nsam]= size(record);%define number of time intervals
nit = nsam/40; %alternative (10s = 10 000ms, 10 000ms/40ms)
%one frame takes 40ms when 25fps (1000ms/25)
%create array with zeros
meanar = zeros(nrows, nit);colours = cell(nrows, nit);%loop for channels 1-23 to determine colours of fragments
%first x of x+1 rows are channels
h=nrows-1;for ch=1:h for i=1:nit j=nit*40; k=j-40; meanar(ch, i) = mean(record(ch,k:j)); if meanar(ch, i)< -300 colours{ch, i}={'black'}; elseif -300<meanar(ch, i)<-200 colours{ch, i}={'violet'}; elseif -200<meanar(ch,i)<-100 colours{ch, i}={'blue'}; elseif -100<meanar(ch,i)<0 colours{ch, i}={'cyan'}; elseif 0<meanar(ch,i)<100 colours{ch, i}={'green'}; elseif 100<meanar(ch,i)<200 colours{ch, i}={'yellow'}; elseif 200<meanar(ch,i)<300 colours{ch, i}={'magenta'}; elseif 300<meanar(ch,i)<400 colours{ch, i}={'red'}; else colours{ch, i}={'white'}; end end%save row of cell to .txt
txtname = sprintf('colours_%s_%d.txt', rec, ch);fileID = fopen(txtname,'w');formatSpec = '%s\n';fprintf(fileID,formatSpec,colours{ch,:});fclose(fileID);end%Unity
%define placement of electrodes on model of the brain
%relate time
%change colours once a 40ms -> change colour of channel (row) x to written in column y
end
Best Answer