help completeing Alphabetical matrix problem

1 view (last 30 days)
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
%Question 3
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);
Your output should look like this :
OutputMatrix = [B B C A C B B C A A;C A C B .. .. .. .. .. ..; .. .. .. .. .. .. .. .. .. ..;
this is what I have so far up my output matrix is incorrect.

Accepted Answer

Kian Azami
Kian Azami on 7 Oct 2017
If your question is understood correctly, by the following code you can create the Alphabetical matrix that you need:
clc
clear all
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];
ABC = {};
for jj = 1:5
for hh = 1:10
X = max([A(jj,hh),B(jj,hh),C(jj,hh)]);
if X == A(jj,hh)
ABC{jj,hh} = 'A';
elseif X == B(jj,hh)
ABC{jj,hh} = 'B';
elseif X == C(jj,hh)
ABC{jj,hh} = 'C';
end
end
end
disp(ABC)

More Answers (1)

Walter Roberson
Walter Roberson on 8 Oct 2017
As discussed in https://www.mathworks.com/matlabcentral/answers/360076-how-to-create-an-matrix-that-is-asked-for-in-the-problem#comment_490771 that required output is not possible in MATLAB, except as a string giving the appearance of the results instead of as an array.

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!