フィルターのクリア

How to call the element in a unknown 2-dim matrix???^_^

1 回表示 (過去 30 日間)
Manqiao Wang
Manqiao Wang 2015 年 10 月 9 日
コメント済み: Manqiao Wang 2015 年 10 月 10 日
This is my first time to use the Matlab. I want to do operations on each element(the index doesn't really matter). However I don't know how to call them if I don't now the size. I should use for or while, and how? (≧∇≦) Btw, I also want to ensure , will the function return 6666 if I tap "disp(6666)"? Thanks a lot~ :)
  1 件のコメント
James Tursa
James Tursa 2015 年 10 月 9 日
Please be more specific. Maybe give a short example showing the inputs and your desired output.

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

採用された回答

Stalin Samuel
Stalin Samuel 2015 年 10 月 9 日
a = randi(2,2);%%your matrix
[r c] = size(a);%%returs no of rows and columns in the matrix a
disp('-------the matrix elements are----')
%%print the elements
for i = 1:r
for j = 1:c
disp(sprintf('%d\n',a(i,j)))
end
end
%%multiply 'a' by 3
a= 3*a

その他の回答 (1 件)

Walter Roberson
Walter Roberson 2015 年 10 月 9 日
x = 1 : 50;
for K = 1 : length(x)
y(K) = x(K).^3 - 10*x(K).^2 - 5;
end
y2 = x.^3 - 10*x.^2 - 5; %same result as y to within roundoff error

カテゴリ

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