"Generate a 2 x 4 matrix variable mat. Verify that the number of elements is equal to the product of the number of rows and columns."

3 ビュー (過去 30 日間)
My professor gave this questiion from the book, but I don't understand what it wants me to do exactly. what does "Verify that the number of elements is equal to the product of the number of rows and columns." mean??
  2 件のコメント
Bruno Luong
Bruno Luong 2019 年 9 月 5 日
編集済み: Bruno Luong 2019 年 9 月 5 日
A = rand(2,4);
neA = numel(A)
nr = size(A,1)
nc = size(A,2)
if neA == nr*nc
fprintf('youhooo\n');
else
% fprintf('Mathworks makes a buggy code!\n');
fprintf('math is an illusion\n');
end
Matt J
Matt J 2019 年 9 月 6 日
My professor gave this questiion from the book, but I don't understand what it wants me to do exactly.
Then why ask us? Why not ask your professor? Your professor understands better than anybody what he/she wants.

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

回答 (1 件)

Star Strider
Star Strider 2019 年 9 月 5 日
There is a function that will do exactly this. If you don’t want to use that function, reshape your matrix to a vector, then determine the number of elements in the vector.

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by