looping through 2 .mat files

1 Ansicht (letzte 30 Tage)
C.G.
C.G. am 27 Okt. 2021
Kommentiert: Mathieu NOE am 19 Nov. 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

Antworten (1)

Mathieu NOE
Mathieu NOE am 27 Okt. 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 Kommentare
Mathieu NOE
Mathieu NOE am 5 Nov. 2021
hello
problem solved ?
Mathieu NOE
Mathieu NOE am 19 Nov. 2021
hello
how is it going ?
problem solved ?
all the best

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Structures finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by