Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The above table represents a color decoding scheme for pixel data. The various c

ID: 3837639 • Letter: T

Question

The above table represents a color decoding scheme for pixel data. The various colors in column 3 are represented by color ID tags listed in column 1 (8-15). write a MATLAB function with header function[ID, COLOR] = pixeldata(A) that will convert an array of pixel codes and produce an output corresponding color and IDs. Consider the following test case: A = [1000, 1111, 1100, 1001, 1001] represents the pixel codes for a small segment, your function should convert this information to: ID = [18, 15, 12, 9, 9] COLOR = Black White Red Blue Blue Develop a pseudo code to solve the above problem. Write the appropriate MATLAB statements for each step. Test your solution by writing a MATLAB function on your computer and submit a print copy/email attachment of your code.

Explanation / Answer

(i) Pseudo code

------------------------

1) ##Initialize the colors array to the given colors

colors = {"Black", "Blue", "Green","Teal","Red","Magneta","Yellow","White"}

2) for in in 1 to size(A)

##convert the binary code to the decimal number, which is id.

id[i] = bin2decimal(A[i])

##using id index the colors array to pick the appropriate color

color[i] = colors[id-7]

end for

(ii) MATLAB instruction for above

-----------------------------------------------

1) colors =["Black"; "Blue"; "Green";"Teal";"Red";"Magneta";"Yellow";"White"];

2) for i = 1:length(A)
dec = 0;
div = A(i);
for k = 1 : 4
dec = dec + mod(div,10) * 2^(k-1);
div = floor(div/10);
end
ID(i) = dec
COLORS(i,:)= colors((dec-7),:)
end

(iii) Complete Matlab function

---------------------------------------------

function [ID, COLORS] = pixeldata(A)
colors =["Black"; "Blue"; "Green";"Teal";"Red";"Magneta";"Yellow";"White"];
for i = 1:length(A)
dec = 0;
div = A(i);
for k = 1 : 4
dec = dec + mod(div,10) * 2^(k-1);
div = floor(div/10);
end
ID(i) = dec;
COLORS(i,:)= colors((dec-7),:);
end

end

A=[1111, 1000, 1111, 1100, 1001, 1001];
[ID, COLORS] = pixeldata(A)

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote