cell strings to matrix
51 views (last 30 days)
Show older comments
Sanwal Yousaf
on 28 Jan 2016
Commented: Star Strider
on 28 Jan 2016
So i had to take a break from this code. I am completely new to cells and strings in matlab. I am trying to get this text file to be broken down to something that i could manipulate. Right now i have been able to isolate the data that i want to use. My problem is two fold:
1. The data file that i use is based on experimental data. Sometimes, the subject doesn't respond to the stimulus and the experimental recorder counts puts that in as MISSED RESPONSE or RESPONDED TO NOTHING or something of that nature. I have isolated the data and the MISSED RESPONSE or RESPONDED TO NOTHING get stored in separate cells in the cell array. Is there any way where i could make them one or have matlab look at any NAN value and discard that whole data row.
2. Can i convert it to, say, a matrix. This code is going to be a part of a bigger data analysis code and most of the data analysis part in it is through matrix. I am guessing that if i keep the data from this code in matrices, it might prevent any inconsistencies that might pop up later on. Although, i might be completely wrong. The code is below, so far, and i am also attaching the text file that i am working on right now.
[filename] = uigetfile('*', 'Select the data file')
import_data = importdata(filename)
[data] = import_data.data
fid = fopen(filename,'r')
scan_init_cell = textscan(fid, '%s %s %s', 'headerlines',20, 'CollectOutput', 1,... 'TreatAsEmpty',{'Responsed','to','Nothing','Missed','Response'})
fclose(fid)
scan_init = [scan_init_cell{:}]
scan_init = scan_init(1:find(~cellfun('isempty',strfind(scan_init,'''''''''''''''''''''''''''''')),1)-1,:)
scan_init_cell = cellfun(@isnan, scan_init, 'un', 0);
0 Comments
Accepted Answer
Star Strider
on 28 Jan 2016
I remember this from one of your previous questions, but not all the details. To convert the entirely numeric data in ‘scan_init_cell’ to a matrix, use the cell2mat function.
If it is not entirely numeric, you likely have to keep it as a cell.
4 Comments
More Answers (0)
See Also
Categories
Find more on Cell Arrays 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!