Borrar filtros
Borrar filtros

csv file to text file

9 visualizaciones (últimos 30 días)
YOGITAA YOGITAA
YOGITAA YOGITAA el 29 de Sept. de 2022
Editada: Jan el 29 de Sept. de 2022
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 comentario
KSSV
KSSV el 29 de Sept. de 2022
How the csv file and what data you want to extract.

Iniciar sesión para comentar.

Respuestas (1)

Jan
Jan el 29 de Sept. de 2022
Editada: Jan el 29 de Sept. de 2022
% [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

Categorías

Más información sobre Text Data Preparation en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by