getting only numbers from an 88x3 cell array.

4 次查看(过去 30 天)
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)

采纳的回答

Star Strider
Star Strider 2016-1-8
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
  8 个评论
Sanwal Yousaf
Sanwal Yousaf 2016-1-14
I found a way to make it work. I used
scan_init = [scan_init_cell{:}]
instead of cell2mat to import the data. Thanks for the help!

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Particle & Nuclear Physics 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by