getting data from structure

1 回表示 (過去 30 日間)
Lichay Malka
Lichay Malka 2020 年 2 月 14 日
回答済み: Geoff Hayes 2020 年 2 月 14 日
Hi!
I have a structure set up like so:
S(1).speed = [x1 y1 z1];
S(2).speed = [x2 y2 z2];
S(3).speed = [x3 y3 z3];
and so on...
for every entry, the speed data is separated into x, y, and z axis in that order.
how can i, for example, get a vector containing only the speed in the x axis of all the entries? (the first object in every entry)

採用された回答

David Hill
David Hill 2020 年 2 月 14 日
T=struct2table(S);
out=T.speed(:,1);

その他の回答 (2 件)

Fangjun Jiang
Fangjun Jiang 2020 年 2 月 14 日
編集済み: Fangjun Jiang 2020 年 2 月 14 日
temp=[S.speed];
out=temp(1:3:end)
% or get all three speeds
Speed=reshape([S.speed],3,[])

Geoff Hayes
Geoff Hayes 2020 年 2 月 14 日
Lichay - you could try something like
speedX = arrayfun(@(k)S(k).speed(1), 1:length(S))
where we use arrayfun to iterate over each element of S and extract the speed in x.

カテゴリ

Help Center および File ExchangeStatistics and Machine Learning Toolbox についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by