looping through 2 .mat files
조회 수: 1 (최근 30일)
이전 댓글 표시
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
답변 (1개)
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
참고 항목
카테고리
Help Center 및 File Exchange에서 Structures에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!