i want to read a csv file and store as rows and columns of a cell

2 ビュー (過去 30 日間)
Sajid Afaque
Sajid Afaque 2020 年 6 月 16 日
コメント済み: Sajid Afaque 2020 年 6 月 16 日
i have a csv file at a particular location. i have attached the csv file.
i want to read the data in the csv file in the below format
and the number of rows and columns are variable.(i.e i do not know how many rows and column may come)
  2 件のコメント
Mohammad Sami
Mohammad Sami 2020 年 6 月 16 日
You can use the readtable function to read the data into matlab.
Sajid Afaque
Sajid Afaque 2020 年 6 月 16 日
i tried its not giving me desired results

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

採用された回答

Stephan
Stephan 2020 年 6 月 16 日
編集済み: Stephan 2020 年 6 月 16 日
fileID = fopen('FOM_HFA_Pavg.csv');
content = textscan(fileID, '%s','Delimiter','\t');
fclose(fileID);
content = content{:};
content = cellfun(@(x)strrep(x,'"',''),content,'UniformOutput',false);
idx = (cellfun('isempty',content));
content(idx) = [];
n = linecount('FOM_HFA_Pavg.csv');
content = reshape(content,[],n)'
% This function was made by Walter and should solve the problem
function n = linecount(filename)
[fid, msg] = fopen(filename);
if fid < 0
error('Failed to open file "%s" because "%s"', filename, msg);
end
n = 0;
while true
t = fgetl(fid);
if ~ischar(t)
break;
else
n = n + 1;
end
end
fclose(fid);
end
  5 件のコメント
Stephan
Stephan 2020 年 6 月 16 日
i edited my previous comment - i think its solved now.
Sajid Afaque
Sajid Afaque 2020 年 6 月 16 日
thank you @stephan and @Walter

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

タグ

製品


リリース

R2013b

Community Treasure Hunt

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

Start Hunting!

Translated by