Why is my coding stopping at the shotscore vector when using fprintf?

load shots.dat;
score = 0;
numbers = (1:1:length(shots))';
x = shots(:,1);
y = shots(:,2);
count = [0 0 0 0 0 0];
shotscore = [];
for i = 1: length(shots)
%Formula for distance
shot = sqrt(((x).^2) + ((y).^2));
if shot(i) <= 29.07
score = score + 10;
count(1) = count(1) + 1;
shotscore(i,:) = 10;
elseif shot(i) <= 62.04 && shot(i) > 29.07
score = score + 8;
count(2) = count(2) + 1;
shotscore(i,:) = 8;
elseif shot(i) <= 95.73 && shot(i) > 62.04
score = score + 6;
count(3) = count(3) + 1;
shotscore(i,:) = 6;
elseif shot(i) <= 129.07 && shot(i) > 95.73
score = score + 4;
count(4) = count(4) + 1;
shotscore(i,:) = 4;
elseif shot(i) <= 162.4 && shot(i) > 129.07
score = score + 2;
count(5) = count(5) + 1;
shotscore(i,:) = 2;
else
score = score + 0;
count(6) = count(6) + 1;
shotscore(i,:) = 0;
end
end
%Calc average distance for shots
avgshot = mean(shot);
%display functions
disp(['Average distance from center of target: ' num2str(avgshot)])
disp(' ')
disp(['Number of shots that earned 10 points: ' num2str(count(1))])
disp(['Number of shots that earned 8 points: ' num2str(count(2))])
disp(['Number of shots that earned 6 points: ' num2str(count(3))])
disp(['Number of shots that earned 4 points: ' num2str(count(4))])
disp(['Number of shots that earned 2 points: ' num2str(count(5))])
disp(['Number of shots that missed the target: ' num2str(count(6))])
disp(' ')
disp('Shot# X-Coord Y-Coord Distance Score')
disp('--------------------------------------------')
fprintf('%3.0f %6.2f %6.2f %6.3f %3.0\n',[numbers x y shot shotscore]')
%plotting code
plot(shot,shotscore,'o')
title('Scores Earned For Each Shot')
xlabel('Shot Distances From Center');ylabel('Score Earned');

Réponses (1)

fprintf('%3.0f %6.2f %6.2f %6.3f %3.0\n',[numbers x y shot shotscore]')
% ^^^^ missing f or g or e or similar similar

Catégories

En savoir plus sur Get Started with MATLAB dans Centre d'aide et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by