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!