フィルターのクリア

Convert file with negative value and nan to double

1 回表示 (過去 30 日間)
Mohamed Asaad
Mohamed Asaad 2022 年 2 月 7 日
コメント済み: Jan 2022 年 2 月 8 日
I am using the below code to import data from another file and to convert commas to dots to be able to plot the values from different files on Matlab. This code works for me except for these two attached files where I get an error message "Conversion to double from struct is not possible." Does anyone know why it does not work for these two files and know a solution for that problem?
a1_Au1EchemPEG = importdata('Au_1_E_chem_experiment_SPR_angle_offset_after_PEG.dat');
b1_Au1EchemPEG = strrep(a1_Au1EchemPEG,',','.');
c1_Au1EchemPEG = cell2mat(cellfun(@str2num,b1_Au1EchemPEG,'un',0));

採用された回答

Jan
Jan 2022 年 2 月 7 日
importdata is extremely smart.Try this:
S = fileread('Au_1_E_chem_experiment_SPR_angle_offset_after_PEG.dat');
S = strrep(S, ',', '.');
D = sscanf(S, '%g', [2, inf]);
  2 件のコメント
Mohamed Asaad
Mohamed Asaad 2022 年 2 月 7 日
Tank you very much! It works for the files that i have atttached in the question.
However, the plot does not work for this new attached file. The code that i have attached in my question worked for this file. Do you know why this is the case?
When i run your code for the the above attached files i get that:
D = 2x2932 double.
But when i run the below code for the new attched file i get:
c1_Au1Echem = [ ]
a1_Au1Echem = fileread('Au_1_E_chem_experiment_SPR_angle.dat');
b1_Au1Echem = strrep(a1_Au1Echem,',','.');
c1_Au1Echem = sscanf(b1_Au1Echem, '%g', [2, inf]);
plot(c1_Au1Echem(1,:), c1_Au1Echem(2,:))
hold on
plot(c1_Au1Echem(1,:), c1_Au1Echem(6,:))
Jan
Jan 2022 年 2 月 8 日
@Mohamed Asaad: The new file starts with a header line, which contains the names of the columns. You can open your .dat files with a text editor to check this.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeData Import and Analysis についてさらに検索

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by