Subscripted assignment dimension problems?

5 ビュー (過去 30 日間)
bio lim
bio lim 2015 年 5 月 25 日
コメント済み: bio lim 2015 年 5 月 25 日
Hello. I have 1x46 structure array called 'data' with numerous fields. I am particularly interested in the 'Time' field. I am trying to use subscripted assignment to calculate the time difference. Below is my code
for n = 1 : length(data)
time_dis(n) = diff(data(n).Time);
end
I know my code is wrong since there are some dimensional errors. Can anyone provide insights? Any help would be greatly appreciated. Thanks.
  1 件のコメント
Stephen23
Stephen23 2015 年 5 月 25 日
What size is each Time variable? Scalar, vector, matrix or array?

サインインしてコメントする。

採用された回答

Stephen23
Stephen23 2015 年 5 月 25 日
編集済み: Stephen23 2015 年 5 月 25 日
If each Time value is one single scalar then you can use this:
diff([data.Time])
You will find this useful to read through and understand:
  4 件のコメント
Stephen23
Stephen23 2015 年 5 月 25 日
Given that each Time values is a 1x40 vector, I would do the following:
>> A(3).Time = [1,2,3,4];
>> A(2).Time = [0,2,4,6];
>> A(1).Time = [0,3,6,9];
>> diff(vertcat(A.Time),1,2)
ans =
3 3 3
2 2 2
1 1 1
bio lim
bio lim 2015 年 5 月 25 日
Thanks!.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by