MATLAB Answers

Prevent overwriting within a for loop in 3D-motion tracking

1 view (last 30 days)
Hi all,
a analyse 3-D motion data in humans. I want to import multiple .xlsx files at once and save the output in one table. So far, in my for loop matlab overwrites the data so that I have only the results in my table with the last iteration (n=21).
Next steps after save all files in one table are to select relevant data and calculate maximum and mean data.
I tried a lot but can't find a solution.
Regards and thank you very much for yout help.
clc; clearvars; close all
data = dir ("*.xlsx") ;
N = length (data) ;
for i = 1:N
thisFile = data(i).name;
T = readtable (thisFile);
end
  2 Comments
Jonas Bender
Jonas Bender on 3 Aug 2021
Dear Sean,
I tried indexing before. Matlab said: "Subscripting into a table using one subscript (as in (t (i)) is not supported. ...
It may be a problem that "thisFile" is a char?
Regards, Jonas
T(i) = readtable (thisFile);

Sign in to comment.

Accepted Answer

Peter Perkins
Peter Perkins on 3 Aug 2021
You may just want
T = table();
for ...
...
T = [T; readtable (thisFile)];
  2 Comments
Peter Perkins
Peter Perkins on 6 Aug 2021
I do: remove the space that I unintentionally put between "readtable" and (thisFile). Oops! Sorry about that!

Sign in to comment.

More Answers (0)

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!