Help with problem?
1 次查看(过去 30 天)
显示 更早的评论
What would the value of d be after the following code is executed?
>> vec = linspace(99,44,56);
>> vec = reshape(vec,8,7);
>> d = vec(length(size(vec(:,3))))
I know that the answer is 98, but I do not understand why. A thorough explanation of this would be appreciated. Thank you.
0 个评论
采纳的回答
TA
2019-10-16
After the second step, you get:
vec =
99 91 83 75 67 59 51
98 90 82 74 66 58 50
97 89 81 73 65 57 49
96 88 80 72 64 56 48
95 87 79 71 63 55 47
94 86 78 70 62 54 46
93 85 77 69 61 53 45
92 84 76 68 60 52 44
Third step: (length(size(vec(:,3)))) equals to 2 if you keep dissecting it. Basically, all columns i.e. vec(:,3) have a size of 8 x 1. And length of that "size" is 2.
And thus, you arrive at vec(2). Which is 98 as I indicated above.
2 个评论
TA
2019-10-16
Yes. Anywhere you see a : that implies all elements are considered.
Length gives you the total number of elements in an array. The array size contains two elements i.e. 8 and 1.
更多回答(0 个)
另请参阅
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!