looping through 2 .mat files
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
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
0 comentarios
Respuestas (1)
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
Ver también
Categorías
Más información sobre Structures en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!