フィルターのクリア

Calculating dot product of 2 3 dimensional row vectors

3 ビュー (過去 30 日間)
Mughees Asif
Mughees Asif 2019 年 2 月 20 日
コメント済み: Mughees Asif 2019 年 2 月 20 日
x=input('Enter the 1st pair of 3 vector elements in [square brackets]: ');
if (x~=3);
disp('The vectors elements cannot contain < or > 3 elements.');
else
y=input('Enter the 2nd pair of 3 vector elements in [square brackets]: ');
if (y~=3);
disp('The vectors cannot contain < or > 3 elements.');
else
z=dot(x,y);
disp('The dot product of the entered vectors is: ');
disp(z)
end
Hi,
I am a new user on MATLAB and trying to figure out what is wrong with the code. After the first line, the code does not respond. Any suggestions would be welcome.
Thank you.
  3 件のコメント
Mughees Asif
Mughees Asif 2019 年 2 月 20 日
編集済み: Mughees Asif 2019 年 2 月 20 日
I inputted x = [1 2] , that should give an error as my 'if statement' states x has to be equal to 3. I am trying to ensure the inputs are always equal to 3 elements.
Rik
Rik 2019 年 2 月 20 日
You are not returning an error, and the code you showed is missing an end.

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

採用された回答

Matt J
Matt J 2019 年 2 月 20 日
編集済み: Matt J 2019 年 2 月 20 日
I think this is what you want:
x=input('Enter the 1st pair of 3 vector elements in [square brackets]: ');
if (numel(x)~=3);
disp('The vectors elements cannot contain < or > 3 elements.');
else
y=input('Enter the 2nd pair of 3 vector elements in [square brackets]: ');
if (numel(y)~=3);
disp('The vectors cannot contain < or > 3 elements.');
else
z=dot(x,y);
disp('The dot product of the entered vectors is: ');
disp(z)
end
end

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMigrate GUIDE Apps についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by