looping through 2 .mat files

1 次查看(过去 30 天)
C.G.
C.G. 2021-10-27
评论: Mathieu NOE 2021-11-19
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

回答(1 个)

Mathieu NOE
Mathieu NOE 2021-10-27
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 个评论
Mathieu NOE
Mathieu NOE 2021-11-19
hello
how is it going ?
problem solved ?
all the best

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Programming 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by