"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 views (last 30 days)
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 Comments
Bruno Luong
Bruno Luong on 5 Sep 2019
Edited: Bruno Luong on 5 Sep 2019
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 on 6 Sep 2019
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.

Sign in to comment.

Answers (1)

Star Strider
Star Strider on 5 Sep 2019
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.

Categories

Find more on Creating and Concatenating Matrices in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!