How to read and plot multiple files
Mostrar comentarios más antiguos
Hi all,
I have multiple output files that i want to proccess at the same time using loops in sequence. Also i want to plot each results 0.02m apart from each other. I have attached the code and my data. Any help will be appreciated.
[filename, pathname] = uigetfile('*.out', 'Select output file to plot');
fullfilename = strcat(pathname, filename);
if filename ~= 0
header.title = h5readatt(fullfilename, '/', 'Title');
header.iterations = double(h5readatt(fullfilename,'/', 'Iterations'));
tmp = h5readatt(fullfilename, '/', 'dx_dy_dz');
header.dx = tmp(1);
header.dy = tmp(2);
header.dz = tmp(3);
header.dt = h5readatt(fullfilename, '/', 'dt');
header.nsrc = h5readatt(fullfilename, '/', 'nsrc');
header.nrx = h5readatt(fullfilename, '/', 'nrx');
% Time vector for plotting
time = linspace(0, (header.iterations - 1) * header.dt, header.iterations)';
% Initialise structure for field arrays
fields.ex = zeros(header.iterations, header.nrx);
fields.ey = zeros(header.iterations, header.nrx);
fields.ez = zeros(header.iterations, header.nrx);
fields.hx = zeros(header.iterations, header.nrx);
fields.hy = zeros(header.iterations, header.nrx);
fields.hz = zeros(header.iterations, header.nrx);
for n=1:header.nrx
path = strcat('/rxs/rx', num2str(n));
tmp = h5readatt(fullfilename, path, 'Position');
header.rx(n) = tmp(1);
header.ry(n) = tmp(2);
header.rz(n) = tmp(3);
path = strcat(path, '/');
fields.ex(:,n) = h5read(fullfilename, strcat(path, 'Ex'));
fields.ey(:,n) = h5read(fullfilename, strcat(path, 'Ey'));
fields.ez(:,n) = h5read(fullfilename, strcat(path, 'Ez'));
fields.hx(:,n) = h5read(fullfilename, strcat(path, 'Hx'));
fields.hy(:,n) = h5read(fullfilename, strcat(path, 'Hy'));
fields.hz(:,n) = h5read(fullfilename, strcat(path, 'Hz'));
fh1=figure('Name', strcat('rx', num2str(n)));
plot(time, fields.ez(:,n), 'r', 'LineWidth', 2), grid on, xlabel('Time [s]'), ylabel('Field strength [V/m]'), title('E_z')
set(ax,'FontSize', 16, 'xlim', [0 time(end)]);
end
end
4 comentarios
Simon Chan
el 1 de Feb. de 2022
Editada: Simon Chan
el 1 de Feb. de 2022
Do you want to plot all results on one figure? And your xlabel mentioned the data is time (not distance) in x-axis, how do you want the data are plotted 0.02m apart?
Kabit Kishore
el 1 de Feb. de 2022
Simon Chan
el 1 de Feb. de 2022
Your data contains information about Field strength [V/m] and time [s] only. Do you need three axis on one plot with a third axis with distance [m]?
Kabit Kishore
el 1 de Feb. de 2022
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Measurements and Feature Extraction 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!


