Hi all. I'm new in MATLAB and in coding in general. I'm practicing but I can't seem to wrap my head around this.
I have a sample data set named 'pre_assign,mat'. It's a structure with 3 tables having varying sizes.
As an example, here's the first table 'pre_assign(1).r_T'
custNo x_coor y_coor d nearest_dist m G p
______ ______ ______ __ ____________ _ _ ______
2 18 16 30 0 2 1 100
7 14 17 20 4.1231 2 1 4.8507
6 16 9 13 7.2801 2 1 1.7857
1 13 6 15 11.18 2 1 1.3416
3 13 6 15 11.18 2 1 1.3416
My end-goal is to get the values of the 'custNo' column that was included in this for-while loop before it terminates:
cumulative_sum = pre_assign(1).r_T.d(1)
C = 64
for qq = [1:5]
while cumulative_sum <= C
cumulative_sum = cumulative_sum + pre_assign(1).r_T.d(1+qq)
end
end
when I run this code above, it ouputs:
cumulative_sum =
30
C =
64
cumulative_sum =
50
cumulative_sum =
70
My questions are the following:
(1) How come that the end result of cumulative_sum is 70? Shouldn't it stopped at pre_assign(1).r_T.d(3) where the actual cumulative sum of column 'd' at that point is 63? (i.e. 30 + 20 + 13 which is < C = 64)
(2) Is it possible to extract the values of column 'custNo' that was included in the loop before it terminated? (i.e. custNo 2, 7, 6)
Any tips or help is greatly appreciated. Thank you.
0 Comments
Sign in to comment.