Write a function in Matlab that would take as input a row matrix.

2 ビュー (過去 30 日間)
Alnuaimi
Alnuaimi 2013 年 11 月 23 日
コメント済み: Alnuaimi 2013 年 11 月 25 日
* Use a for loop to compute the square of each element in A and store the square values in matrix B.
function [B] = Square(A)
* Recall the function file that you created from the command window to take an input A=1:10
* Use plot function to plot B versus A
Can anyone help me understand the question so i can try solving it?
will i be using arrays in this problem? and how will i plot a graph?

採用された回答

Image Analyst
Image Analyst 2013 年 11 月 23 日
You can do this all in one m-file. Have an m-file called test_square.m and in there have both the test harness (calling function) and the Square function. It will look similar to this:
function test_square()
A = 1:10;
B = Square(A);
plot(A, B, 'ro-');
grid on;
function B = Square(A)
for k = 1 : length(A)
B.......
.... and so on.
In the loop you square each element of A because this is exactly what it told you to do. Then just click the green triangle, or type test_square on the command line, to run the program.
  3 件のコメント
Image Analyst
Image Analyst 2013 年 11 月 24 日
r means red. o means to put a little circle at the data point. - means to connect the data points with a solid line between them.
Alnuaimi
Alnuaimi 2013 年 11 月 25 日
Thanks a lot for the help!

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

その他の回答 (1 件)

Walter Roberson
Walter Roberson 2013 年 11 月 23 日
Hint:
for K = 1 : 20
B(K) = A(K) + 5; %for example
end

カテゴリ

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