### Translated by

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

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

plank008

### plank008 (view profile)

さんによって質問されました 2019 年 3 月 19 日

### dpb (view profile)

さんによって コメントされました 2019 年 3 月 21 日
John D'Errico

### John D'Errico (view profile)

さんの 回答が採用されました
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

plank008

### plank008 (view profile)

2019 年 3 月 19 日
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.
dpb

### dpb (view profile)

2019 年 3 月 20 日
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...
Guillaume

### Guillaume (view profile)

2019 年 3 月 20 日
"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 件の回答

2019 年 3 月 20 日

### John D'Errico (view profile)

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.
char(toeplitz(65:70))
ans =
6×6 char array
'ABCDEF'
'BABCDE'
'CBABCD'
'DCBABC'
'EDCBAB'
'FEDCBA'
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'
'B'
'C'
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.

Guillaume

### Guillaume (view profile)

2019 年 3 月 20 日
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.
dpb

### dpb (view profile)

2019 年 3 月 20 日
"... 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 course...in that case the special case of only the vector array is possible since Matlab arrays are rectangular.
John D'Errico

### John D'Errico (view profile)

2019 年 3 月 21 日
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.

2019 年 3 月 21 日

### plank008 (view profile)

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!"

dpb

### dpb (view profile)

2019 年 3 月 21 日
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