Info

此问题已关闭。 请重新打开它进行编辑或回答。

ok so I am trying to create a legend that can change if the number of datasets included in the read excel file is changed. How would I go about doing this? Here is the full code so you can get an idea of whats going on.

2 次查看(过去 30 天)
ffscores=xlsread('Fantasy_football_scores.xlsx');
[number name]=xlsread('Fantasy_Football_players .xlsx');
[num_rows num_cols]=size(ffscores);
for i=1:num_rows
[saved_max index]=max(ffscores(i,:));
fprintf('The winner of week %0.0f is %s with a score of %0.0f.\n',i, name{index},saved_max)
end
[saved_max index]=max(ffscores(:));
[num_row num_col]=ind2sub(size(ffscores),index);
fprintf('The winner of the entire league is %s with a score of %0.0f.\n',name{num_col},saved_max)
for i=1:num_cols
x=[1:num_rows];
Y=ffscores(:,i);
y=Y.';
plot(x,y)
hold on
xlabel('Week');
ylabel('Scores');
title('Fantasy Football Scores');
legend('Luis-Miguel','Joseph','Ethan');
grid on
end

回答(1 个)

dpb
dpb 2017-5-5
The answer to the question is just
hL=legend(name); % legend for each name read
as long as you keep internal order consistent.
Can streamline code some..."Use the vectors, Luke!" :)
fmt1='The winner of week %2d is %s with a score of %0.1f.\n';
fmt2='The winner of the entire league is %s with a score of %0.1f.\n'
[number name]=xlsread('Fantasy_Football_players .xlsx');
[saved_max index]=max(ffscores,[],2); % max for each row, location
[r c]=size(ffscores);
for i=1:r
fprintf(fmt1,i, name{index(i)},saved_max(i))
end
[saved_max index]=max(sum(ffscores)); % max column sums/total for all weeks
fprintf(fmt2,name{index},saved_max) % column is the index
hL=plot(ffscores.'); % save line handles; might want to modify
xlabel('Week');
ylabel('Scores');
title('Fantasy Football Scores');
legend(name);
grid on

此问题已关闭。

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by