Error in formatting csv files imported from python

1 回表示 (過去 30 日間)
Avishek Mukherjee
Avishek Mukherjee 2022 年 5 月 18 日
Hi,
I am trying to format two csv files imported from Python. The following set of commands work fine for one csv file but raises error with another csv file. The two csv files are of the same type, the only difference are the data. I am confused as to why one is working while the other doesn't work.
rawdata = readcell('medcoordsdof.csv'); % Use readcell
data = cellfun(@(x) strtrim(erase(x,{'[' ']'})),rawdata(2,:),'uni',0); % Remove the characters such as '[' & ']'
datacell = cellfun(@(x) str2double(strsplit(x,' ')),data,'uni',0);
The above code works fine with the attached medcoordsdof.csv file.
However, the same lines of code raises error for the adcoordsdof.csv file. For example,
rawdata = readcell('adcoordsdof.csv'); % Use readcell
data = cellfun(@(x) strtrim(erase(x,{'[' ']'})),rawdata(2,:),'uni',0); % Remove the characters such as '[' & ']'
datacell = cellfun(@(x) str2double(strsplit(x,' ')),data,'uni',0);
raises the error:
Error using erase (line 40)
First argument must be text.
Error in Bfield>@(x)strtrim(erase(x,{'[',']'})) (line 4)
data = cellfun(@(x) strtrim(erase(x,{'[' ']'})),rawdata(2,:),'uni',0); % Remove the characters such as '[' & ']'
Error in Bfield (line 4)
data = cellfun(@(x) strtrim(erase(x,{'[' ']'})),rawdata(2,:),'uni',0); % Remove the characters such as '[' & ']'
Any help or suggestion would be extremely useful and will be greatly appreciated.
Thank you.

回答 (0 件)

カテゴリ

Help Center および File ExchangeCall Python from MATLAB についてさらに検索

タグ

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by