Write a MATLAB function called myelecusage with one input, a list of 5 numbers, representing the individual measurements from an electric meter dial guage and returns the tota

5 views (last 30 days)
I need to write this function, but I am not sure how to make the input a list of numbers instead of just one value. The input is a list of values and then the output is the combination of those numbers in backwards order.
The input needs to be a list of values, ex. [1,2,3,4,5], and the output would be 54321 kwh.
function [TEM] = myelecusage(v1,v2,v3,v4,v5)
TEM = v5.*10000 + v4.*1000 + v3.*100 + v2.*10 + v1
end
It works whenever I put in arbitrary values, but it does not work when I use the test cases I am given.
I am given these two test cases:
Test case 1:
myelecusage([3, 0, 8, 9, 3])
ans = 39803
Test case 2:
readings=[0, 2, 8, 1, 0]
kwhr = myelecusage (readings)
kwhr=1820
can someone please help?

Answers (1)

Sulaymon Eshkabilov
Sulaymon Eshkabilov on 3 Feb 2023
Here is the corrected answer:
ANSWER =myelecusage([3, 0, 8, 9, 3])
ANSWER = 39803
readings=[0, 2, 8, 1, 0];
kwhr = myelecusage ([readings])
kwhr = 1820
function TEM = myelecusage(v)
TEM = v(5)*10000 + v(4)*1000 + v(3)*100 + v(2)*10 + v(1);
end

Categories

Find more on Testing Frameworks in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!