I'm trying to create a 57x1 matrix out of the con_data 57x4 matrix/variable, and then plot that matrix from the userinput. But avg_energy is an unrecognised function/variable
1 次查看(过去 30 天)
显示 更早的评论
Code for continent selection:
function [continent, con_data] = choose_continent()
% prompt messaged displayed in command window
disp('Choose a continent in the menu to view its fossil fuel consumption');
% menu to choose continent
all_continents = {'Africa', 'Asia', 'Europe', 'North America', 'Oceania', 'South and Central America'};
while true
continent = menu('Choose a contient', all_continents{:});
if continent ~= 0
break
end
% if a continent isn't selected and menu closed then an error messaged is
% displayed and the menu is reopened
disp('Error! Please selected a continent.');
end
% store the continent name
continent = all_continents{continent};
% stores the correct file name for the chosen continent
file_name = [strrep(strrep(continent,' and ',''),' ','') '.xlsx'];
% loads the corresponding data for the chosen continent
con_data = xlsread(file_name);
code for average engery consumption each year graph:
%gets an average of the energy consumption for each year
function choose_plot(avg_energy, continent)
con_matrix = con_data(:,2:4)
avg_energy = mean(con_matrix,2)
%opens a new figure window
figure
hold on
plot(avg_energy, 'W--o')
%set x axis labels to the years
xtixks(1:57)
xticklabels({'1965', '2021'})
xlabel('Years')
hold off
end
Attached is one of the 6 continent excel files
0 个评论
采纳的回答
Voss
2022-12-16
Seems like con_data (rather than avg_energy) would be an input to choose_plot, since choose_plot calculates avg_energy from con_data:
% code for average engery consumption each year graph:
function choose_plot(con_data, continent) % note: input "continent" is unused
con_matrix = con_data(:,2:4)
avg_energy = mean(con_matrix,2)
%opens a new figure window
figure
hold on
plot(avg_energy, 'W--o') % note: this plots a white line
%set x axis labels to the years
xticks(1:57) % note: that's a lot of ticks
xticklabels(1965:2021) % note: that's a lot of labels
xlabel('Years')
hold off
end
0 个评论
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!