how to create an matrix that is asked for in the problem
2 views (last 30 days)
Show older comments
Write Matlab code that creates a new 5x10 matrix that creates an alphabetical matrix that displays the letter of the matrix that has the HIGHEST value of the 3 matrices A,B,C from Problem #1 on an element by element basis.
I have this code so far
A = [12 3 56 78 3 4 5 10 91 21; 16 18 3 5 7 17 4 7 10 11;
2 4 6 8 10 12 10 6 3 19; 1 22 8 9 12 7 17 5 8 10;
7 6 2 1 45 8 17 8 9 16];
B = [16 81 18 3 5 7 9 12 9 11; 0 2 3 7 82 6 9 15 12 10;
7 4 1 1 8 7 15 43 11 17; 8 3 1 0 1 0 4 5 9 16;
7 6 2 1 45 8 17 8 9 16];
C = [6 7 68 24 13 2 8 16 22 2; 67 13 4 5 9 11 16 12 22 1;
13 14 15 9 64 41 12 11 10 3; 2 0 1 4 6 1 6 2 3 3;
8 5 6 4 2 5 60 25 13 3];
m = max( max (A,B), C);
vars = {'A', 'B','C',};
mask1 = m == A;
mask2 = m == B;
mask3 = m == C;
which_one = cell(size(m));
which_one(mask1) = vars(1);
which_one(~mask2) = vars(2);
which_one(mask3) =vars(1|2)
but I cant get the output that the instructor shows
OutputMatrix = [B B C A C B B C A A;C A C B .. .. .. .. .. ..; .. .. .. .. .. .. .. .. .. ..;
.. .. .. .. .. .. .. .. .. ..; .. .. .. .. .. .. .. .. .. ..;]
can can someone help/elaborate please.
1 Comment
Answers (1)
Walter Roberson
on 6 Oct 2017
1 Comment
Walter Roberson
on 7 Oct 2017
OutputMatrix = [B B C A C B B C A A;C A C B .. .. .. .. .. ..; .. .. .. .. .. .. .. .. .. ..;
.. .. .. .. .. .. .. .. .. ..; .. .. .. .. .. .. .. .. .. ..;]
It is not possible to get that output in MATLAB, except as by converting the entire array to character and displaying it. There are no MATLAB data types that will display character entities without apostrophes or double quotes around them.
One thing that would be possible is to have the equivalent of
OutputMatrix = ['B B C A C B B C A A';'C A C B .. .. .. .. .. ..'; '.. .. .. .. .. .. .. .. .. ..';
'.. .. .. .. .. .. .. .. .. ..'; '.. .. .. .. .. .. .. .. .. ..';]
Then, disp(OutputMatrix) would display as
B B C A C B B C A A
C A C B etc
but you would have to disp() it to get it to show up that way.
To do this, you would have to insert the spaces between each of the array elements.
See Also
Categories
Find more on Multidimensional Arrays 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!