Problem 1981. Time and Variable mapping and matching
There is a 6X5 cell array where
- 1st column represents time values
- 2nd and 3rd column represent variables and their values respectively
- 4th and 5rd column represent variables and their values respectively
Note that same variable can be used in columns 2 and 4, but not in same rows Sample cell array is shown below:
X = {'0','a','1', '', ''; '1','b','2', '', ''; '2', '', '','c','3'; '3', '', '','d','4'; '4','e','1','' , ''; '5', '', '','d','6'};
Output should be variables with name of variables used in array along with Time variable (1st column). Default Values of these variables (a,b,c,d,e) will be 0 at time = 0 (except if it is explicitly set eg: a=1 at time=0). Variables will continue to hold the set values except when they are explicitly set. Output of above example will be 1-D column vectors of time, a, b, c, d, e with following values:
Time a b c d e 0 1 0 0 0 0 1 1 2 0 0 0 2 1 2 3 0 0 3 1 2 3 4 0 4 1 2 3 4 1 5 1 2 3 6 1
Solution Stats
Problem Comments
-
4 Comments
suggestion: please change the testsuite line that reads "assert(isequal(your_fcn_name(x),y_correct))" to [Time,a,b,c,d,e]=your_fcn_name(X); assert(isequal([Time;a;b;c;d;e],y_correct));
Done. Many Thanks.
I believe you still would need to add back the line "y_correct=[Time;a;b;c;d;e];" right before the line "[Time,a,b,c,d,e]=your_fcn_name(X);" for the testsuite to work?
Sorry, my mistake.Thanks.
Solution Comments
Show commentsProblem Recent Solvers15
Suggested Problems
-
1901 Solvers
-
234 Solvers
-
88 Solvers
-
Create a square matrix of multiples
475 Solvers
-
Determine the number of odd integers in a vector
731 Solvers
More from this Author10
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!