Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

How do i select the datafile with the smallest lenght?

조회 수: 1 (최근 30일)
Sam
Sam 2014년 12월 22일
마감: MATLAB Answer Bot 2021년 8월 20일
I've got a 5x5 matrix (data_stair_rise), and each cell is a struct. Each struct contains a datafile called 'VideoSignals'. I need to select the datafile which has the smallest length. How do I do this?
When I open 'data_stair_rise' it looks like this: data_stair_rise(1, 1). Now there is an overview of datafiles and 'VideoSignals' is one of them.

답변 (2개)

Image Analyst
Image Analyst 2014년 12월 22일
Why not just use dir() to select the file with the fewest number of bytes in it?
fileInfo = dir(filename);
bytesInFile = fileInfo.bytes;
  댓글 수: 2
Sam
Sam 2014년 12월 23일
fileInfo = dir(data_sts)
Error using dir Function is not defined for 'struct' inputs.
Image Analyst
Image Analyst 2014년 12월 23일
I said to pass it a filename , not a structure, like dir('yourMatFile.mat') or whatever.

Guillaume
Guillaume 2014년 12월 23일
Your question is a bit confusing because you're not using the proper terminology. A structure does not contain datafile. A structure is made of fields.
Length can also have several meaning. Matlab's own length function returns the size of the largest dimension (and thus is best avoided). I'll assume here you want the matrix / vector with least number of elements, so I'll use numel instead.
One way to do what you want:
data1d = data_stair_rise(:); %reshape data_stair_rise as a 1D array to make the rest easier
signallengths = arrayfun(@(elem) numel(elem.VideoSignals), data1d);
[~, idx] = min(signallengths);
smallestsignal = data1d(idx).VideoSignals;

이 질문은 마감되었습니다.

태그

Community Treasure Hunt

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

Start Hunting!

Translated by