Transpose a vector under certain conditions

8 ビュー (過去 30 日間)
Kat
Kat 2019 年 10 月 6 日
コメント済み: Kat 2019 年 10 月 6 日
Write a function that will receive two column vectors as input arguments, and from them create and return a matrix with two columns (n × 2). If either of both of the vectors passed in are row vectors, transpose them into column vectors. If either input is a matrix, your program should throw a unique error (Create your own error message). You may not assume that the length of the vectors is known. I can use the transpose operator, the size function and length function to do this. I need the format to do this under these conditions. I've tried multiple ways but I keep getting errors. What should I do?Thanks!
  3 件のコメント
Kat
Kat 2019 年 10 月 6 日
Screenshot (86).png
Kat
Kat 2019 年 10 月 6 日
編集済み: Kat 2019 年 10 月 6 日
The question I asked is part of a bigger question. I was able to solve all the other tasks correctly except the two tasks I intially mentioned

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

採用された回答

Steven Lord
Steven Lord 2019 年 10 月 6 日
If this were not a homework assignment, you'd probably want to use the isrow, iscolumn, and/or isvector functions.
Since I'm guessing your professor doesn't want you to use those functions, I'd still write it in terms of those functions but then comment out those functions and replace them with your own code that does the same thing. The comments would then serve as documentation of the purpose of the code that you've written.
Some useful test cases you can use to test that portion of your function's input checking:
R = 1:5;
C = 5+R.';
makemat(R, R)
makemat(R, C)
makemat(C, R)
makemat(C, C)
  1 件のコメント
Kat
Kat 2019 年 10 月 6 日
Thank you so much for the amazing help and clarification!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by