3 件のコメント

madhan ravi
madhan ravi 2020 年 10 月 2 日
in what context?
Barbara Fiorani
Barbara Fiorani 2020 年 10 月 2 日
An example of exercise: Find the Dth row of H (i.e. row 2) and sum all the elements in that row.
Considering that I have already created matrix H.
madhan ravi
madhan ravi 2020 年 10 月 2 日
What did you try for your homework?

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

 採用された回答

Walter Roberson
Walter Roberson 2020 年 10 月 2 日

0 投票

It means that you have a variable named D and that you want the value of D to indicate which row number of H to access. If D had value 7 then you would want the "seventh" row. If it had value 8 then you would want the "eighth" row. If it had value 19, you would want the "nineteenth".
Explicit values such as 7 are "Cardinal" numbers -- numbers that tell you how much of something there is.
Designations such as "first" ("1st"), "second" ("2nd"), "third" ("3rd") are known as "Ordinal" numbers, and talk about the position of something. https://www.mathsisfun.com/numbers/cardinal-ordinal-nominal.html
So when refering to wanting to use the value stored in D as a position to look at, English would often use Ordinals -- most of which end in "th" in English. To refer to D as designating an Ordinal (position) English might then refer to the row . might also be written as or as . It means much the same thing as using the content of D as counting the number of rows that need to be dealt with (with the implication that the first (D-1) are not being paid attention to.)

2 件のコメント

Barbara Fiorani
Barbara Fiorani 2020 年 10 月 2 日
Thank you.
If, in this case, Dth row is H row 2, and matrix H is : H = 1 3
5 0
6 8
why matlab gives me sum= 2 2 instead of 5 when I want to sum all the numbers in row 2 of matrix H?
Walter Roberson
Walter Roberson 2020 年 10 月 2 日
I would need to see your code.

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

その他の回答 (1 件)

madhan ravi
madhan ravi 2020 年 10 月 2 日

0 投票

Dth stands for the row 2 , index it to the matrix and use sum().

5 件のコメント

Barbara Fiorani
Barbara Fiorani 2020 年 10 月 2 日
I have tried the following:
sumDth=sum(2,H)
sumDth=sum[H(2,:)]
but none worked, matlab reported as error.
Am I typing incorrectly?
thank you.
madhan ravi
madhan ravi 2020 年 10 月 2 日
sumDth = sum(H(2,:))
Barbara Fiorani
Barbara Fiorani 2020 年 10 月 2 日
Thank you.
However, it recognize it as error. The same happen when I simulate a vector that holds the sum of 10 six-sided dice 1000 times (which you can initially create in a 1000 by 10 matrix). I have typed the following:
dice=rand(6,1000,10);
sumdice=sum(dice,2);
Still, in the second step (sum), it signal it as error.
madhan ravi
madhan ravi 2020 年 10 月 2 日
What?
Walter Roberson
Walter Roberson 2020 年 10 月 2 日
You should not be using rand() for this purpose. You should be using randi() .

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

カテゴリ

ヘルプ センター および File ExchangeVariables についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by