MATLAB: Getting only numbers from an 88×3 cell array.

arraycell arraysmatrix arraymatrix manipulation

I have imported my data from a text file which is attached below.I have successfully imported the data into matlab but now i want to extract specific data labeled under the Calculated Reaction time so far and now the Raw reaction time. The number of calculated reaction time readings can change depending on the subject who was taking the test. I am trying to have the code check for numbers in all three columns of each row and if the response is missing or not recorded to discard that reading and keep going on with checking if it the remainder rows are all numerical. I also want it to truncate when it hits the '''''''' before the Raw reaction times. My code, so far, is as follows:
% feed the data file here with the reaction times.
[filename] = uigetfile('*', 'Select the data file')
% This function imports the reaction data from the file
import_data = importdata(filename)
[data] = import_data.data
fid = fopen(filename,'r')
scan_init_cell = textscan(fid, '%s %s %s', 'headerlines',18, 'CollectOutput', 1)
%scan_init = cell2mat(scan_init_cell{:})
for 1:size(scan_init_cell{:},1):
cellfun(@isnumeric(scan_init_cell{:},1)
fclose(fid)

Best Answer

This will read your file and do what you want. If there are string responses other than {'Responsed to Nothing','Missed Response'}, you will have to include them in the 'TreatAsEmpty' cell in the textscan call.
fidi = fopen('Sanwal Yousaf USE_THIS.txt','r');
scan_init_cell = textscan(fidi, '%f%f%f', 'HeaderLines',20, 'CollectOutput',1, 'TreatAsEmpty',{'Responsed to Nothing','Missed Response'});
fclose(fidi);
scan_init = cell2mat(scan_init_cell);
scan_init = scan_init(~isnan(scan_init(:,3)),:); % Omit Rows With ‘NaN’ In Column #3