How to extract data selection from multiple .txt files and plot one graph?
Mostrar comentarios más antiguos
Hello everyone,
I have multiple .txt files like the one (please, check the .txt file enclosed). The data of interest is these two specific columns "Zreal" and "Zimag" (it can be seen in the image below):

I've created to scripts. One named 'read_gamry_data' and the other 'nyquist_gamry'.
Here is the code 'read_gamry_data'
% EDIT: adding function call so errors are displayed here (CL)
data = read_gamry_data('Sample Potentiostatic EIS.txt')
function [data] = read_gamry_data(fname)
%READ_GAMRY_DATA Gets the data matrices in the file "fname" and
%stores them into the cell "data"
%get all lines of the file
stra = {};
fid=fopen(fname,'r');
sl = fgetl(fid);
while ischar(sl)
stra{end+1,1}=strtrim(sl);
sl = fgetl(fid);
end
fclose(fid);
%get the EIS data from the gamry .txt files
strid_dataset = 'ZCURVE';
id_start = [];
data = cell(length(id_start),1);
for y = 1:length(id_start)
for z = id_start(y):id_end(y)
if strcmp(strid_dataset,stra{z}(1:min(length(stra{z}),length(strid_dataset))))
%read data matrix
rstart = z+3;
rend = rstart;
while rend<=id_end(y) && length(split(stra{rend}))>1
rend = rend+1;
end
rend = rend-1;
break;
end
end
data{y}=zeros(rend-rstart+1,length(split(stra{rstart})));
for z = rstart:rend
data{y}(z-rstart+1,:)=(sscanf(stra{z},'%f'))';
end
end
end % added this CL
and here is the code of 'nyquist_gamry' script. Before just plotting, I need to correct the data by the area, so I tried:
clear all;close all;
dir_files = 'EIS'
area = (pi/4)*1.5^2
fname = dir(fullfile(dir_files,'*.txt'));
for a = 1:length(fname)
data{a} = read_gamry_data(strcat(dir_files,'/', fname{a}));
data{a}{1}(:,1:2) = area.*data{a}{1}(:,1:2);
plotgraph(1,data{a}{1}(:,1),-data{a}{1}(:,2))
hold on
end
xlabel('Z_{real}(\Omega.cm^2)', 'FontSize', 12)
ylabel('-Z_{imag}(\Omega.cm^2)','FontSize', 12)
set(gca,"dataaspectratio",[1,1,1])
I constantly having errors, especially saying that my index is not supported. Can anyone try to run it and see if you can help me with? I would like to hear any suggestion from you all.
Kindly
Leandro
1 comentario
Cris LaPierre
el 16 de Abr. de 2024
Editada: Cris LaPierre
el 16 de Abr. de 2024
I edited your code so that it could be run here. The sample file does not generate any errors, but the final result is also empty, so yout code is not properly loading the data..
Please share the full error message (all the red text).
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Environment and Settings en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

