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