Counting the number of instances when the user selects the correct answer

1 view (last 30 days)
Hi Everyone,
I constructed a quizz where users can select the answers from a dropdown and when they slect the correct answer a textbox appears when they click the submit button showing if they got the answer correct. Now, the issue I have is that i want to count the number of times the user gets an answer correct. Can anyone assist please?
The snippet of the code is shown below:
value = app.CoherenceBandwidthDropDown.Value;
app.Coherencebandwidth.Visible ='on';
if strcmpi(value,'the reciprocal of the multipath spread, which provides a measure of the bandwidth over which frequency components of the transmitted signal will be affected similarly by the channel')
app.Coherencebandwidth.Value='Answer is correct!';
else
app.Coherencebandwidth.Value='Answer is incorrect!';
end
value1 = app.PowerDelayProfileDropDown.Value;
app.PDP.Visible ='on';
if strcmpi(value1,'represents the average power of the received signal in terms of the delay with respect to the first arrival path in multi-path transmission ')
app.PDP.Value='Answer is correct!';
else
app.PDP.Value='Answer is incorrect!';
end
value2 =app.EvaporationductDropDown.Value;
app.Evaporationduct.Visible ='on';
if strcmpi(value2,'is a refractive layer that results from the rapid decrease in humidity level with altitude')
app.Evaporationduct.Value ='Answer is correct!';
else
app.Evaporationduct.Value ='Answer is incorrect!';
end
value3 = app.CoherencetimeDropDown.Value;
app.Coherencetime.Visible ='on';
if strcmpi( value3,'measures the time interval over which the channel response will change very little and is the reciprocal of the doppler spread')
app.Coherencetime.Value='Answer is correct!';
else
app.Coherencetime.Value='Answer is incorrect!';
end
value4=app.LineofsightpropagationDropDown.Value;
app.LOS.Visible ='on';
if strcmpi( value4,'between two points for which the direct ray is sufficiently clear of obstacles for diffraction to be of negligible effect')
app.LOS.Value='Answer is correct!';
else
app.LOS.Value='Answer is incorrect!';
end
value5=app.ShadowingDropDown.Value;
app.shadowing.Visible ='on';
if strcmpi( value5,'is the power fluctuation due to obstruction between the transmitter and receiver ')
app.shadowing.Value='Answer is correct!';
else
app.shadowing.Value='Answer is incorrect!';
end
value6=app.ScatteringDropDown.Value;
app.Scattering.Visible ='on';
if strcmpi( value6,'The spreading of waves in non-uniform manner over an area')
app.Scattering.Value='Answer is correct!';
else
app.Scattering.Value='Answer is incorrect!';
end
value7=app.DopplerSpreadDropDown.Value;
app.Dopplerspread.Visible ='on';
if strcmpi( value7,'widening of the spectrum of a narrow-band signal transmitted through a multipath propagation channel')
app.Dopplerspread.Value='Answer is correct!';
else
app.Dopplerspread.Value='Answer is incorrect!';
end
value8=app.MultipathPropagationDropDown.Value;
app.Multipathpropagation.Visible ='on';
if strcmpi( value8,'Propagation of the same radio signal between a transmission point and a reception point over several separate propagation paths')
app.Multipathpropagation.Value='Answer is correct!';
else
app.Multipathpropagation.Value='Answer is incorrect!';
end
value9=app.ElevatedductDropDown.Value;
app.Elevated.Visible='on';
if strcmpi( value9,'tropospheric radio-duct in which the lower boundary is above the surface of the Earth')
app.Elevated.Value='Answer is correct!';
else
app.Elevated.Value='Answer is incorrect!';
end
value10=app.SurfacebasedductDropDown.Value;
app.Surfacebased.Visible='on';
if strcmpi( value10,'tropospheric radio- duct that is caused by the temperature inversion due to the advection of warm and dry air over the ocean or cooling of the land.')
app.Surfacebased.Value='Answer is correct!';
else
app.Surfacebased.Value='Answer is incorrect!';
end
value11=app.SurfaceductDropDown.Value;
app.Surfaceduct.Visible='on';
if strcmpi( value11,'A tropospheric radio-duct in which the lower boundary is the surface of the Earth')
app.Surfaceduct.Value='Answer is correct!';
else
app.Surfaceduct.Value='Answer is incorrect!';
end

Accepted Answer

David Rodriguez
David Rodriguez on 1 Mar 2021
Edited: David Rodriguez on 10 Mar 2021
I think there are multiple ways you could do this. I am not an expert but I would make a 1XN vector of zeros. Then change the N value in the matrix to 1 every time they got something correct. Then sum all the ones at the end.
value = app.CoherenceBandwidthDropDown.Value;
app.Coherencebandwidth.Visible ='on';
% Create array of zeros
answerValues = zeros(1,num_questions);
if q1 = correct
app.Coherencebandwidth.Value='Answer is correct!';
answerValues(1) = 1;
else
app.Coherencebandwidth.Value='Answer is incorrect!';
end
if q2 = correct
app.PDP.Value='Answer is correct!';
answerValues(2) = 1;
else
app.PDP.Value='Answer is incorrect!';
end
...
num_correct = sum(answerValues);

More Answers (0)

Categories

Find more on Mathematics in Help Center and File Exchange

Products


Release

R2020b

Community Treasure Hunt

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

Start Hunting!