0
votes

I have a text file containing my data looking like this:

3,848E-05
3,848E-05
3,848E-05
3,848E-05
3,848E-05
3,848E-05
3,848E-05
3,848E-05
3,848E-05 
2,3088E-05
-0,00013468

I have tried using load and get an error telling me that the ASCII file must contain the same number of columns per lines.

fname1 = fullfile(path,'test1.txt');
emg1 = load(fname1);


Error using load
Number of columns on line 233 of ASCII file must
be the same as previous lines.

I've also tried using importdata and that couldn't deal with this kind of number format. Any ideas? I'm using MATLAB 2014a.

fname1 = fullfile(path,'test1.txt');
emg1 = importdata(fname1);

This is how the imported data looked like using importdata.

3   0.00848000000000000
3   0.00848000000000000
3   0.00848000000000000
3   0.00848000000000000
3   0.00848000000000000
3   0.00848000000000000
3   0.00848000000000000
3   0.00848000000000000
3   0.00848000000000000
2   0.0308800000000000
-1  0.00924000000000000
1
Please upload your code and associated errors in a minimal reproducible example - Adriaan

1 Answers

0
votes

The problem seems due to the fact that the values in the file contains , (comma) instead of . (dot).

In this cse, you can

  • read the input file as a text file (containing string)รน
  • replace the , with .
  • convert the string to number (double)

A possible solution could be:

% Open the input file
fp=fopen('d.txt','rt')
% Read the file as a text file
C=textscan(fp,'%s')
% Close the text file
fclose(fp)
% Convert the string to numbers
x=str2num(char(strrep(C{1}(:),',','.')))

Hope this helps.

Qapla'