how to find rows and columns without using size

7 ビュー (過去 30 日間)
Hanwool Yun
Hanwool Yun 2019 年 9 月 14 日
コメント済み: Adam Danz 2019 年 9 月 15 日
Introductory MATLAB course, haven't covered loops and such yet. I'm curious how to find rows + columns of an array without using size fxn? Obv numel()/length() give you rows + columns, but they don't tell you which is which. What to do next?
  4 件のコメント
Guillaume
Guillaume 2019 年 9 月 15 日
What is the actual text of the assignment, not your interpretation of it?
An assignment that asks you to find the size of a matrix without using the size function would be completely absurd. Sure you can find all sorts of roundabout ways of doing it, none of which would teach you anything useful and all of them requiring more advanced knowledge than the size function.
Adam Danz
Adam Danz 2019 年 9 月 15 日
^^ my thoughts exactly.

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

回答 (2 件)

Bruno Luong
Bruno Luong 2019 年 9 月 14 日
編集済み: Bruno Luong 2019 年 9 月 14 日
for 2D array
p=numel(A);
if p==0
try
r = A(1,:);
n = 0;
m = numel(A*zeros(0,1));
catch
m = 0;
m = numel(zeros(1,0)*A);
end
else
m = numel(A(:,1));
n = p/m;
end
  2 件のコメント
Hanwool Yun
Hanwool Yun 2019 年 9 月 14 日
unfortunately we haven't covered loops yet, is there any way to do this with basics, like using length and numel and indexing?
Bruno Luong
Bruno Luong 2019 年 9 月 14 日
loop? which loop?

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


Bruno Luong
Bruno Luong 2019 年 9 月 15 日
[numel(prod(A,2)) numel(prod(A,1))] % prod instead of sum for a change

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by