any simplified way to get the length of each variable in structure

4 Ansichten (letzte 30 Tage)
Yu Li
Yu Li am 27 Apr. 2019
Kommentiert: Yu Li am 27 Apr. 2019
Hi:
I have a structure, each element of the structure has a different size, which is what I neede.
it is very easy to write a for-loop to get it, but I want know if there is any easier way?
Please see attached test file, and below is the test code:
for i=1:1:length(test)
sz(i)=length(test(i).a);
end
Bests,
Yu

Akzeptierte Antwort

Matt J
Matt J am 27 Apr. 2019
sz = arrayfun(@(t) length(t.a), test);

Weitere Antworten (1)

madhan ravi
madhan ravi am 27 Apr. 2019
arrayfun(@(x)length(x.a),test) % use numel if the variables are a vector , I didn’t download your file so not sure how your variables are but this seems to do what you want.

Kategorien

Mehr zu MATLAB finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by