Borrar filtros
Borrar filtros

How to import data correctly from the attatched .csv file?

1 visualización (últimos 30 días)
opts = detectImportOptions('Compare for L100 and L150\Result_R-970_W-10um_C-LRL-C_Model.csv','TrimNonNumeric',true,'NumHeaderLines',1);
T2 = readtable('Compare for L100 and L150\Result_R-970_W-10um_C-LRL-C_Model.csv',opts);
T2.Properties.VariableNames={'freq','Z'};
I am using this code to import data from the attached file into a table, however the 2nd column in file is Real + j Imaginart value and this code is only saving Real part into Z and not saving the entire complex part into Z. How can I rectify that?
Note:
  • Even if we manage to get the complex part into a single column, I think matlab may take it as a string because A+iB is not valid in MATLAB. MATLAB syntax for complex number is A+Bi
  • Even if we manage to delimit at +/- sign same syntax problem still exist.
Edit: I am also adding another file format(TAB limited .txt) with same data, please show code to extract from that format as well.

Respuesta aceptada

Ameer Hamza
Ameer Hamza el 10 de Sept. de 2020
Editada: Ameer Hamza el 10 de Sept. de 2020
Try textscan()
f = fopen('Result_R-640_W-10um_C-LRL-C_Model.csv');
data = textscan(f, '%f GHz,%f %s j%f', 'HeaderLines', 12);
fclose(f);
s = cellfun(@(x) 2*(x=='+')-1, data{3});
t = table(data{1}, data{2}+s.*data{4}*1i, 'VariableNames', {'freq','Z'});
  3 comentarios
Ameer Hamza
Ameer Hamza el 10 de Sept. de 2020
I am glad to be of help!
See the updated code for a general solution.
Prabhanshu Chandra
Prabhanshu Chandra el 10 de Sept. de 2020
Oh thankyou! This generalised code works well too.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Tables en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by