Question
Function Name: graphcmp Inputs: 1. ( char ) A MxN char array representing a bar graph 2. ( char ) A KxL char array representing
Function Name: graphcmp
Inputs:
1. ( char ) A MxN char array representing a bar graph
2. ( char ) A KxL char array representing a misformated bar graph
Outputs:
1. ( char ) A formatted string describing the mistakes in the second graph
Topics: ( masking ), ( array operations )
Background:
You are a hardworking intern at CS1371 Corp and have compiled some performance
data on different employees to help your boss decide who should get a raise at the end of the
quarter. However, your boss can be a bit of a dunce and has messed up your nicely formatted
graphs! You must now find the differences between the two graphs and inform your boss of how
they messed up!
Function Description:
You are given two char arrays that represent bar graphs. The first array contains your
correctly formatted bar graph. In your array, each EVEN column will represent a bar on your
graph. The ODD columns contain only white space ( ' ') to help your graph be more visually
appealing. Starting from the bottom of the array, the bars are made of an arbitrary character that
is NOT a space ( ' ' ). The second array is messed up and may have any number of the
following errors: (1) the bars themselves may consist of a different character, (2) the bar heights
may be different, (3) the second array may have been reshaped so the array dimensions are
incorrect and the graph is unreadable.
You must determine how many bars in the second bar graph are incorrect. First, you
should ensure your second array has the same dimensions as the first array. Second, you
should compare the heights of each bar between the two graphs to count the number of bars
that are different. Output the number of bars with incorrect heights in a string that follows the
format: 'My boss' graph has
where numIncorrectBars is the number of bars in the second graph that are of a different
height than the first graph.
myGraph =
[' '
' # '
' # # '
' # # # '];
bossGraph =
[' % '
' % %'
' '
' % '
' % '
' % '];
str = graphcmp(myGraph, bossGraph);
str 'My boss' graph has 3 bars that need fixed!'
Notes:
The even columns of myGraph have been highlighted for visual clarity, this is not a part
of the problem.
Every column with an even index in the graph counts as a bar, even if that bars value is
zero.
The first and last column of the graph will always contain only spaces.
You are guaranteed to have at least 1 bar in every graph
You will always have the same number of bars for both graphs
A bar of correct height but incorrect character does not have to be fixed and is not to be
counted in the output
Hints:
The reshape() function may be useful
Masking might help you figure out the size of each bar
When including an apostrophe in a string, use '' (2 apostrophes) to tell MATLAB that
the apostrophe is not supposed to be the end of the string
Please Solve using matlab! To receive a thumbs up DO NOT USE CONDITIONAL STATEMENTS(if, else, elseif) or ITERATIONS (loops) in you solution code!! Example inputs have been added so they can be copied and pasted into matlab. A picture of the example provided for clarity!
Example: myGraph bossGraph = ! ! ! # # 1 ']; do op op ']; Example: myGraph bossGraph = ! ! ! # # 1 ']; do op op ']Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started