Subtracting in a structure
16 ビュー (過去 30 日間)
古いコメントを表示
Hi, Sorry if some stuff doesnt make sense as I'm quite new to matlab!I have 1 x 229 struct array with 13 fields. One of the fields is a total number which adds up consecutively from a count.
Pass(NumPass).TotalPlayers = Count3
I'm trying to find a way to minus these numbers from each other so the difference is added to a SortedTotalPlayers field, so if the first 5 numbers in the TotalPlayers field were: 6,10,12,16,26, I would want the first 5 numbers in the SortedTotalPlayers field to be 6,4,2,4,10.
Pass(NumPass).SortedTotalPlayers = ?
I haven't realy got a clue what to put after the = sign, is this possible?
Thanks
0 件のコメント
回答 (3 件)
dpb
2021 年 11 月 21 日
Pass(NumPass).SortedTotalPlayers = diff[0 Pass(NumPass).SortedTotalPlayers];
0 件のコメント
Image Analyst
2021 年 11 月 21 日
Try this:
NumPass = 1;
Pass(NumPass).TotalPlayers = [6,10,12,16,26];
firstNumber = Pass(NumPass).TotalPlayers(1); % Get the "6"
Pass(NumPass).SortedTotalPlayers = [firstNumber, diff(Pass(NumPass).TotalPlayers)]
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Matrices and Arrays についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!