Subscripted assignment dimension problems?

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일

0 개 추천

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

bio lim
bio lim 2015년 5월 25일
Thanks for your answer. The problem is that they are not a single scalars. Each data.Time, such that data(1).Time is a 1x40 vector. This is why I am considering to use a loop. Do you have any idea how to do this? Thanks!
bio lim
bio lim 2015년 5월 25일
Your link was very useful! Thanks!
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개)

카테고리

도움말 센터File Exchange에서 Logical에 대해 자세히 알아보기

제품

질문:

2015년 5월 25일

댓글:

2015년 5월 25일

Community Treasure Hunt

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

Start Hunting!

Translated by