How do I make a randomized test on Matlab?
古いコメントを表示
Below is my code. I am trying to have matlab give me a random question and then it tell me if I am right or wrong based on my answer. As you can see I am typing in units and it keeps saying that kg, m, and s are unrecognizable functions. Here is my code.
QandA={'what is metric units for Acceleration? ', 'm/s^2';
'what is metric units for Density? ', 'kg/m^3';
'what is metric units for Energy,Heat,Work? ', '(kg*m^2)/s^2';
'what is metric units for Force? ', '(kg*m)/s^2';
'what is metric units for Length? ', 'm';
'what is metric units for Mass? ', 'kg';
'what is metric units for Power? ', '(kg*m^2)/s^3';
'what is metric units for Pressure? ', 'kg/(m*s^2)';
'what is metric units for Temperature? ' 'K';
'what is metric units for Time? ', 's';
'what is metric units for Volume? ', 'm^3';};
qorder = randperm(numel(QandA(:,1)));
QandAreordered = QandA(qorder, :);
for qidx=1:size(QandAreordered, 1)
answer=input(QandAreordered{qidx, 1}); %double
if (answer == str2double(QandAreordered{qidx, 2})) %string to double
fprintf('Correct\n', '%s');
else
fprintf('Incorrect\n', '%s');
end
end
Please help me ASAP if possible. I am using this to study for an Exam I have next week.
1 件のコメント
The '%s' in those fprintf calls is unnecessary because it's ignored by fprintf since the first argument (e.g., 'Correct\n') has no formatting operators.
fprintf('Correct\n') % this is sufficient
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Networks についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!