The m-file create_cell_example.m creates a cell array with the average monthly p
ID: 3863306 • Letter: T
Question
The m-file create_cell_example.m creates a cell array with the average monthly precipitation values for three cities. The array also contains the names of the cities, the names of the precipitation types and strings containing abbreviations of the months of the year. Start with the template file exercise_template.m to create an m-file (named “exercise_.m”) that produces a bar chart of the average monthly rainfall and snowfall for Minneapolis. You must use cell-array indexing to access the strings for use in the title, legend and x-axis tick labels.
% cell_exercise.m
clear all
close all
% Call the m-file that creates the cell array
create_cell_example
% assign the array of rain/snow values from City 2 to a 2x12 matrix
ap2(1:2,:) = ????????
% create a bar chart of both the rain and snow values for City 2
bar(1:12,????)
% set the XTickLabel for gca to use the month abbreviations
set(gca,'XTickLabel',??????)
% specify the ylabel
?????
% Specify the title using the name string for City 2
title(horzcat('Average Monthly Precipitation for ',????????))
% Set the legend utilizing the precipitation name strings
?????
______________________________________________________________________
%% create_cell_example.m
clear all
close all
% Call the m-file that creates the cell array
create_cell_example
% assign the array of rain/snow values from City 2 to a 2x12 matrix
ap2(1:2,:) = ????????
% create a bar chart of both the rain and snow values for City 2
bar(1:12,????)
% set the XTickLabel for gca to use the month abbreviations
set(gca,'XTickLabel',??????)
% specify the ylabel
?????
% Specify the title using the name string for City 2
title(horzcat('Average Monthly Precipitation for ',????????))
% Set the legend utilizing the precipitation name strings
?????
Explanation / Answer
you plot all the data first, and then manipulate the Legend using per example cells as shown below :
In case there are many legends, like N plots, then you do :
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.