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

5 views (last 30 days)
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 Comments
dpb
dpb on 20 Mar 2019
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...
Guillaume
Guillaume on 20 Mar 2019
"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.

Sign in to comment.

Accepted Answer

John D'Errico
John D'Errico on 20 Mar 2019
Edited: John D'Errico on 20 Mar 2019
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.
  3 Comments
dpb
dpb on 20 Mar 2019
"... 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 on 21 Mar 2019
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.

Sign in to comment.

More Answers (1)

plank008
plank008 on 21 Mar 2019
Edited: plank008 on 21 Mar 2019
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 Comment
dpb
dpb on 21 Mar 2019
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.

Sign in to comment.

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!