필터 지우기
필터 지우기

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

조회 수: 1 (최근 30일)
Jonas Bender
Jonas Bender 2021년 8월 3일
댓글: Peter Perkins 2021년 8월 6일
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
Sean Brennan
Sean Brennan 2021년 8월 3일
In the line:
T = readtable (thisFile);
This command overwrites the prior T value. An easy fix for this is to index the variable, one for each table: For example:
T(i) = readtable (thisFile);
In subsequent processing, you can then again do a loop over the tables to generate the analysis for each. For example:
for ith_table = 1:length(T)
% Do your analysis on each table here, where each table can be recovered
% as T(ith_table)
end
Jonas Bender
Jonas Bender 2021년 8월 3일
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);

댓글을 달려면 로그인하십시오.

채택된 답변

Peter Perkins
Peter Perkins 2021년 8월 3일
You may just want
T = table();
for ...
...
T = [T; readtable (thisFile)];
  댓글 수: 2
Jonas Bender
Jonas Bender 2021년 8월 3일
Dear Peter,
this looks like a quite good solution. creating an empty table and fill this table. However, when I tried yout code an error message occured:
Error using readtable. Not enough input arguments.
Do you have an explanation?
Jonas
Peter Perkins
Peter Perkins 2021년 8월 6일
I do: remove the space that I unintentionally put between "readtable" and (thisFile). Oops! Sorry about that!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by