looping through 2 .mat files

1 visualización (últimos 30 días)
C.G.
C.G. el 27 de Oct. de 2021
Comentada: Mathieu NOE el 19 de Nov. de 2021
I have 2 matlab files with data in. Im trying to get my code to loop through both files and put the data into the 6 pre-assigned matrix.
I am getting the error:
Unable to perform assignment because the left and right sides have a different number of elements.
timestep = height(vel);
time_sec = timestep/100;
inputrate = 1;
%% Files
files = dir('*.mat');
num_files = length(files);
%% Data output
resGT = zeros(100000,2);
GTflucc = zeros(100000,2);
mean_GT = zeros(numel(files),1);
std_GT = zeros(numel(files),1);
max_GT = zeros(numel(files),1);
min_GT = zeros(numel(files),1);
for a = 1:100000
load(files(a).name)
v = vel;
resGT(a) = sqrt(v(:,1).^2 +v(:,2).^2 + v(:,3).^2);
GT2 = resGT.^2;
GTflucc(a) = sqrt(cumsum(GT2)./time_sec);
%stats
mean_GT(a) = mean(resGT);
std_GT(a) = std(resGT);
max_GT(a) = max(resGT);
min_GT(a) = min(resGT);
end

Respuestas (1)

Mathieu NOE
Mathieu NOE el 27 de Oct. de 2021
hello
had to modify a bit your code to make it work
try this :
clc
clearvars
% timestep = height(vel); % are not yet defined (after load only)
% time_sec = timestep/100; % idem
inputrate = 1;
%% Files
files = dir('*.mat');
num_files = length(files);
%% Data output
resGT = zeros(100000,2);
GTflucc = zeros(100000,2);
mean_GT = zeros(numel(files),1);
std_GT = zeros(numel(files),1);
max_GT = zeros(numel(files),1);
min_GT = zeros(numel(files),1);
for a = 1:num_files
load(files(a).name)
v = vel;
timestep = height(vel);
time_sec = timestep/100;
resGT = sqrt(v(:,1).^2 +v(:,2).^2 + v(:,3).^2);
GT2 = resGT.^2;
GTflucc = sqrt(cumsum(GT2)./time_sec);
%stats
mean_GT(a) = mean(resGT);
std_GT(a) = std(resGT);
max_GT(a) = max(resGT);
min_GT(a) = min(resGT);
end
  8 comentarios
Mathieu NOE
Mathieu NOE el 5 de Nov. de 2021
hello
problem solved ?
Mathieu NOE
Mathieu NOE el 19 de Nov. de 2021
hello
how is it going ?
problem solved ?
all the best

Iniciar sesión para comentar.

Categorías

Más información sobre Programming 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