How to get numerical values of a text type cell ?

Hi,
I am trying to read the contents of a .txt file, which is the frequency response data I got from other simulation software. The following shows the format of the data, which has 'Frequency' and 'Real/Imaginary' part of the frequency response.
Capture.JPG
I tried using 'readtable()' to load the data into MATLAB, which works. However, the loaded data is in 'Cell' format, and I am not able to get the actual value of the data, please see following.
Capture.JPG
My question is (1) how can I get the actual values ? (2) Is there any better way to do the job than 'readtable()' ? Thanks for help!

 Risposta accettata

T = readtable(FileName, 'Delimiter', ' ,');

6 Commenti

T = readtable(FileName, 'Delimiter', ' ,', 'MultipleDelimsAsOne', true);
Hi Walter,
Thanks for help! I tried this method, but it still doesn't work, please see the result I got:
filename = fullfile('.\EMI_Buck_Experiment_1ohm.txt');
% T = readtable(filename);
T = readtable(filename, 'Delimiter', ' ,', 'MultipleDelimsAsOne', true);
Capture.JPG
(1) Original variable name are changed, which is fine; (2) the 2nd column combined with 1st column.
Walter Roberson
Walter Roberson il 28 Feb 2019
Modificato: Walter Roberson il 28 Feb 2019
Please attach a sample file. There could be something subtle like tabs that I cannot see in the image. This current image makes it look like there is no delimiter between columns in your input.
Hi Walter,
Please see the attached data file. Thanks.
T = readtable(filename, 'Delimiter', '\t,');
You did indeed have a tab.
Hi Walter,
Thanks for your time and help! It works now.

Accedi per commentare.

Più risposte (1)

Hi Star, Walter,
Thanks for your help. Using 'Delimiter' still doesn't seem to work, I tried that, and the second column of data combined with the first column data with a new comma in between.
I actually write a short .m file to manually remove the comma and get the data I want. Not very efficient, but not quite harmful for my case.
function [Real,Imag] = Get_R_I(Resp)
len = length(Resp);
Real = zeros(len,1);
Imag = zeros(len,1);
for i = 1: len
comma = find( Resp{i} == ',' );
Real(i) = str2double(Resp{i}(1:comma-1));
Imag(i) = str2double(Resp{i}(comma+1:end));
end
end

Categorie

Community Treasure Hunt

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

Start Hunting!

Translated by