Filter löschen
Filter löschen

getting only numbers from an 88x3 cell array.

4 Ansichten (letzte 30 Tage)
Sanwal Yousaf
Sanwal Yousaf am 8 Jan. 2016
Kommentiert: Star Strider am 14 Jan. 2016
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)

Akzeptierte Antwort

Star Strider
Star Strider am 8 Jan. 2016
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 Kommentare
Sanwal Yousaf
Sanwal Yousaf am 14 Jan. 2016
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!
Star Strider
Star Strider am 14 Jan. 2016
My pleasure!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by