-1

I'd like to read into matlab my .rad file which is like that :

https://www.dropbox.com/s/w057nsnvquzrc18/RAD.rad?dl=0

I tried to use textscan and this :

D = textscan(fid, '%f %f %f %f %f','Delimiter',' ','headerlines', 19);

I got this :

enter image description here

Thanks for the help.

YLM
  • 335
  • 6
  • 17
  • 1
    You've specified that the delimiter is a comma, and are confused why the data is being split at the commas? Specify the delimiter as a space instead... – Wolfie Nov 18 '17 at 17:36
  • Thanks! ..but it does not work, I got an error : Dimensions of matrices being concatenated are not consistent. So If I remove the cell2mat, it's a bit better but I get NaN value if each column... @Wolfie – YLM Nov 18 '17 at 17:41
  • 1
    **1.** Please edit your question to include an actual excerpt from the file, instead of an image, so we can copy and paste it to run your code ourselves. **2.** I have no idea what the output looks like before or after you took my advice, because you haven't shown us. Edit your question to include the outputs you're getting as well as what your *expected* output is. – Wolfie Nov 18 '17 at 17:51
  • You should add the text of your file here (minimal text required to reproduce the problem) instead of referring to external links. – Sardar Usama Nov 18 '17 at 17:59

1 Answers1

1

You can try:

  • reading the numerical data as "string"
  • replace the "comma" with a "dot"
  • convert the cellarray to a char array
  • convert the string to number with the function str2num

a possible implementatino could be:

fid=fopen('RAD.rad','r')
% Read the data as strings
x=(textscan(fid, '%s', 'headerlines', 19))

% Remove the last row (string: END OF FILE)
x{1}(end-2:end)=[];

fclose (fid)

% Define the number of variables
n_vars=5
% Get the number of data
n_data=length(x{1})
% Identify the number of rows
n_rows=n_data/n_vars
data=str2double(strrep(x{1},',','.'));
the_data=reshape(data,n_vars,n_rows)'

Edit following the comments of the OP

I've tested the code with the file you've posted.

I've updated the code to discard the last line of the input (since it is the string "END OF FILE").

The x variable is {11550x1 cell} so the data are stored in x{1}.

The second part of the code, generate the matrix the_data which contains the datra read from the inout file.

>> whos the_data
  Name             Size            Bytes  Class     Attributes

  the_data      2310x5             92400  double   
halfer
  • 19,824
  • 17
  • 99
  • 186
il_raffa
  • 5,090
  • 129
  • 31
  • 36
  • `str2num` uses `eval` within it. Use `str2double` instead. – Sardar Usama Nov 18 '17 at 17:53
  • Helps a lot. Thanks. In x I got 5 cell and in each one I have my column 1 by 1. So it's quiet nice, I could use it! Thank you very much. It could be better if I could have my data in a whole matrix, but I can work with those data. In data I got NaN so the reshape does not work ! Thanks – YLM Nov 18 '17 at 18:04
  • I've updated the code, you have to discard the last line of your input file. – il_raffa Nov 18 '17 at 18:30
  • @SardarUsama thanks for the suggestion, I've upodated the code. – il_raffa Nov 18 '17 at 21:20