1

A MATLAB struct was created:

filenameSubstring='C:\Data\**/*.json';
filenames = dir(filenameSubstring);

The attempt to evaluate the mean was unsuccessful:

sizemean = mean(filenames.size);

Attempts to create an array was not successful in that it returned only one value:

test=(filenames(:).bytes)

I could put the access the each element using a for loop:

for i= 1:size(filenames,1)
    test(i)=filenames(i).bytes;
end

Is there a concise one-liner that can move all .bytes elements into an array for further evaluation?

1 Answer 1

5

Yes:

[filenames.bytes]

filename.bytes generates a comma-separated list of values, equivalent to filename(1).byes, filename(2).bytes, filename(3).bytes, .... The square brackets concatenate these into an array. The above is thus the same as

[filename(1).byes, filename(2).bytes, filename(3).bytes, ... ]
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.