Not able to Extract DATA from Row and Column

I got the code below that is meant to extract specific signals and their corresponding data from .dat file. and output them in a table / row and column with signal name and data. however my FS_DATA is not correct what have I done wrong ? the SIGNAL 1x32 struct with 6 while the DATA is 6906x32 double.
[DATA SIGNALS] = tmsread('A359_FIB2_F817.dat');%read data and gives back DATA and SIGNALS names
FS_list= {};%empty cell to populate with Filtered FS signals
n=0;%count
for i=1:length(SIGNALS)
if strfind(upper(SIGNALS(i).Name),'FS')%filter throught the SIGNALS list and locates FS only signals
n = n+1;%count
FS_list{n} = SIGNALS(i).Name;%populates the FS signals
end
end
FS_data=cell(size(DATA,1),size(FS_list,1)); %extract the corresponding DAT for EachFSsignal
for i=1:length(FS_list)
FS_data{:,i},DATA(:,i); %creates a table/ row and column with FS signals and its DATA
end

8 Comments

Can you upload A359_FIB2_F817.dat ?
I have uploaded a small version of a Dat file A359_FIB2_F817.dat is a huge file. Note within these .dat files there are units and time series values that are not taken into account when you convert this to xlsx or csv
What is tmsread?
in house command that reads all of the data from FILE. DATA is an MxN matrix, where M is the number of samples, and N is the number of variables.SIGNALS is a 1xN structure, containing the details of the returned signals.
FS_data{:,i},DATA(:,i);
Is not valid matlab syntax. What is the intent of the above?
Oh! And which version of matlab are you using?
I aim using matlab2016b and the intent was to create a row and column and populate them with the DATA and signals. I have found a fix as below
[DATA SIGNALS] = tmsread('A359_FIB2_F817.dat');
var = {};
%populates the empty cell with SIGNALS names
for i = 1:length(SIGNALS)
var{i} = SIGNALS(i).Name;
end
x=contains(var,'FS') & ~contains(var,'AFS') ;
indx = find(x==1);
varindx = [1 indx];
dat = DATA(:,varindx);
sig = var(varindx);
disp(sig)
disp(dat)
xlswrite('output',sig);
xlswrite('output',dat,['A2:' char(65+size(dat,2)-1) num2str(size(dat,1)+1)]);
however as the file number of rows ancolumns is too many I get the error below: The specified data range is invalid or too large to write to the specified file format any help on this ?

Sign in to comment.

 Accepted Answer

A much simpler version of your code which should work in R2016b:
[data, signals] = tmsread('A359_FIB2_F817.dat');
signames = {signals.Name}; %no need for a loop for that
tokeep = contains(signames, 'FS') & ~contains(signames, 'AFS');
datatokeep = data(:, [true, tokeep]); %no need for find
writetable(array2table(datatokeep, 'VariableNames', ['xxx', signames(tokeep)]), 'output.xlsx');

3 Comments

@Guillaume what is XXX? and thanks for your answer. works however I get an error at the end when creating a table saying AFDX/VL_BCS_COM_1_FWS_CDS/BCS_COM_FWS_CDS_1/FDS_01_ANTI_SKID_STATUS/FS_01_ANTI_SKID_STATUS is not a Valid Variable name ?
The 'xxx' was the header for the first column that I thought you didn't name. But rereading your code, I misunderstood and it's a mistake anyway.
Since your signal names can't be easily changed into variable names, it's back to xlswrite for writing the excel file:
[data, signals] = tmsread('A359_FIB2_F817.dat');
signames = {signals.Name}; %no need for a loop for that
tokeep = contains(signames, 'FS') & ~contains(signames, 'AFS');
tokeep(1) = true; %always keep first column
datatokeep = data(:, tokeep); %no need for find
xlswrite('output.xlsx', signames(tokeep), 'Sheet1');
xlswrite('output.xlsx', datatokeep, 'Sheet1', 'A2');

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!