csv file to text file

조회 수: 5 (최근 30일)
YOGITAA YOGITAA
YOGITAA YOGITAA 2022년 9월 29일
편집: Jan 2022년 9월 29일
Hi ,
I want to generate a text file for the chosen csv file by extracting some values from the specific index and not to read the whole csv.
Please let me know
Thanks in advance :)
  댓글 수: 1
KSSV
KSSV 2022년 9월 29일
How the csv file and what data you want to extract.

댓글을 달려면 로그인하십시오.

답변 (1개)

Jan
Jan 2022년 9월 29일
편집: Jan 2022년 9월 29일
% [UNTESTED CODE!]
function Value = GetCSVElement(File, R, C)
% INPUT: File: File name
% R: Row index of wanted element. 1 row for the header assumed.
% C: Column index of wanted element
[fid, msg] = fopen(File, 'r');
assert(fid > 0, msg);
for k = 1:R + 1
s = fgetl(fid);
end
fclose(fid);
if isequal(s, -1)
error('File %s has less than %d rows.', File, R);
end
V = strsplit(s, ',');
if numel(V) < C
error('Row %d of file %s has less than %d columns.', R + 1, File, C);
end
Value = sscanf(V{C}, '%g');
end

카테고리

Help CenterFile Exchange에서 Text Data Preparation에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by