Determine specific length file

5 views (last 30 days)
Jonas
Jonas on 4 Jan 2015
Edited: Stephen23 on 4 Jan 2015
Hi,
I want to determine the length of the file in the image(in the attached file), but without the sts-files.
if I try this: i_execution=1:length(data(1).files_c3d), I get the whole length of the file (ans=8). What should i write to get the length without the sts-files?
  2 Comments
Stephen23
Stephen23 on 4 Jan 2015
Edited: Stephen23 on 4 Jan 2015
This does not pertain to the length of a file, as the title states, but rather to the length of some values contained in a variable "data" which is clearly located in the workspace (in a particular a part of that variable "data(1).files_c3d"). Although this variable appears to have been extracted from a file, this seems to be irrelevant to the length operation requested here.
Jonas
Jonas on 4 Jan 2015
Edited: Jonas on 4 Jan 2015
I want to make 2 different loops:
first loop->use files with stair: i_execution=1:length(data(1).files_c3d) (ans=5)
second loop->use files with sts: i_execution=1:length(data(1).files_c3d) (ans=3)
Is there a way to execute this?

Sign in to comment.

Accepted Answer

Stephen23
Stephen23 on 4 Jan 2015
Edited: Stephen23 on 4 Jan 2015
It appears from the screenshot that your data is contained within a structure array. You should read about structures:
particularly how to extract data from them:
The original question is not clear, but it appears that you wish to determine which elements of the structure belong to certain groups, based on the strings contained within the field 'name'. You can easily determine this using strcmp or strncmp :
A = {'stair_1','stair_2','stair_3','stair_4','stair_5','sts_1','sts_2','sts_3'};
B = {'A','B','C','D','E','F','G','H'};
C = struct('name',A,'blah',B);
X = strncmp('stair',{C.name},5);
You can then use the index X to refer to only those parts of the struct C where 'name' starts with the characters 'stair':
B(X)
Or the remaining parts of the struct:
B(~X)
Note that in your case the struct C is nested inside another struct, so your actual indexing might look something like data(1).files_c3d.name. You can experiment with the indexing to return the correct parts of the struct that you need.
A loop can be achieved using find on the index X or ~X, but actually may not be necessary:. Many functions in MATLAB allow you to perform operations on whole matrices at once, avoiding the need for 'for' loops entirely.

More Answers (0)

Categories

Find more on Structures in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!