MATLAB Answers

Translated by

このページのコンテンツは英語から自動翻訳されています。自動翻訳をオフにする場合は「<a class="turn_off_mt" href="#">ここ</a>」をクリックしてください。


is it possible to create a Character array using a vertical vector of characters?

さんによって質問されました 2019 年 3 月 19 日
最新アクティビティ dpb
さんによって コメントされました 2019 年 3 月 21 日
I have this question as part of a review sample quiz but i am confused about how to go with it. I think it is possible to create a character array using the char( ...) function. I also tested this to create a vertical vector and it is working. z=['A'; 'B'; 'C']. so I am really confused abou what this question is actually asking for. please give a thorough explanation of how to determine the wrong statement or statements among the choices. THANK YOU!
Character arrays can be constructed by either of the following EXCEPT:
A.) Using a special version of the char(…) cast function
B.) Using a vertical vector of characters
C.) Using a vertical vector of characters of the same length
D.) A and B
E.) A and C

  4 件のコメント

unfortunately I will need to review on this type of questions because the exam is going to be exactly like this type of questions. the instructor doesn't care and is letting one of his TAs write exams and quizes for us to take.
I feel your pain...
Well, either of B or C is viable so since D and E each include one of those, then they're out leaving only A...
But it's still poorly posed at best including "either" which imples "or" and is a choice between two and there are five choices given...
"the instructor doesn't care and is letting one of his TAs write exams and quizes for us to take."
Your institution should have a formal procedure for you to complain about the standard of the exams.
It should also have a standard procedure for creating exams. Where I work, this includes having the exam questions checked by an independent moderator to ensure that this sort of things don't happen. If that procedure has not been followed it's all the more reason for you to complain formally.

サインイン to comment.

2 件の回答

回答者: John D'Errico
2019 年 3 月 20 日
編集済み: John D'Errico
2019 年 3 月 20 日

Sadly, answers A, B, and C are all virtual drivel, as is the entire question. The difference between options B and C is silly. And since options D and E are just combinations of A,B,C, you are lost in the matter.
The fact is, one can trivially create a character array using char as it is. No special version of char is needed. So A is sort of correct, I guess, except that nothing special is necessary. Here is a cute way that uses the nothing special function char, as well as toeplitz for fun.
ans =
6×6 char array
If you can create just one vertical vector of characters, then a character array is always possible to create. In fact, a vector is itself a special case of an array. So B can easily be argued to be technically correct. And you need only one vector to create an array. For example,
V = 'ABC'.'
V =
3×1 char array
A = repmat(V,[2 5]);
creates a 6x5 array of characters from a single character vector. And this next variation creates a 2x2 array, from one vertical vector.
V = 'ABCD'.';
A = reshape(V,[2 2]);
Certainly the latter example is one where only a single vector was needed to create an array, and no horizontal catenation of vertical vectors was ever needed.
Since the reshape variation involves no catenation of vertical vectors at all, B is arguably a solution method.
Finally, C is also a solution method, since V1 and V2 are vectoral vectors of characters, each of length 4. And you can only horizontally catenate vertically oriented vectors together if they are the same length.
V1 = 'ABCD'.';
V2 = 'ABCD'.';
A = [V1,V2];
So C appears to be a solution method.
My guess is, the person who wrote the question, thinks that B is NOT a solution method, because they think the requirement of equal length vectors was important. However, since I showed two methods to create such a character array from one vector alone, B is arguably correct.
And here is a method to create a 3x2 character array from two vertically oriented vectors of different lengths.
V1 = 'AB'.';
V2 = 'DEFG'.';
A = reshape([V1;V2],[3,2]);
Even so, I'd bet the poser of the question thinks B is not correct, because I can give an example of vertically oriented vectors of arbitrarily different lengths where it will be more difficult to create a character array. (Probably not impossible, mind you, as I can always get more creative.) I think the poser is focusing on the idea that the only way to create an array is by horizontal concatenation, and therefore all vectors must have the same lengths. Note that the last example used vertical concatenation.
And the person who writes the question and also grades those tests will always be technically correct in their assesment as far as you are concerned.
So, I agree. I do feel for you in this matter. To be honest, I have a funny feeling that if the entire test is written in as confusing a way as this one sample question seems to be, thus multiple choice with no good answer to the question, I'm not confident I would get more than a C or D on the test, if I passed at all. And if I cannot ace a basic test about MATLAB, there is a problem.

  3 件のコメント

To me option C is meaningless. What is the length of a character? (1?) What are characters of the same lengths? A vertical vector means that the number of columns is 1.
None of the answer are valid for me.
"... just one vertical vector of characters, then a character array is always possible to create. In fact, a vector is itself a special case of an array."
As long as numel() isn't prime, of that case the special case of only the vector array is possible since Matlab arrays are rectangular.
I would claim that who ever wrote this question should be stripped of their MATLAB license. All of the answers are highly ambiguous, subject to liberal interpretation errors.

サインイン to comment.

回答者: plank008
2019 年 3 月 21 日
編集済み: plank008
2019 年 3 月 21 日

thank you so much everyone for your insight! I talked to my advisor about the situation and she also suggested to start a formal report about the situation at my department. It seems like this instructor have been reported for a different issue before becsaue as soon as I mensioned his name in the office they were all shaking their heads like "oh no! not again!"

  1 件のコメント

That's good to know...thanks for reporting back.
Incompetence is rampant but there's no reason to have to pay what tuition is these days to be taught such...
Some of it can probably be attributed to the language issues, but there's too much else wrong to simply ignore.

サインイン to comment.

Translated by