Problem 767. Assign numerical values to a structure with 1 field
The aim is to assign values to a multidimensional structure without using for-loop or while-loop
Example with a structure 2*3:
s = repmat(struct('prices', 0), 2, 3);
data = [11 12 13 ;21 22 23 ];
The expected output s2 will be the following structure 2*3:
s2(1,1).prices = 11 s2(1,2).prices = 12 s2(1,3).prices = 13 s2(2,1).prices = 21 s2(2,2).prices = 22 s2(2,3).prices = 23
Rules:
1) Using For-loops or While-loops is prohibited
2) For this problem the structure will always have a single field. In the above example s has an unique field "prices".
3) However the name of this field can be changed
Have fun!
Solution Stats
Problem Comments
Solution Comments
Show commentsProblem Recent Solvers34
Suggested Problems
-
6080 Solvers
-
Sum all integers from 1 to 2^n
17363 Solvers
-
Project Euler: Problem 8, Find largest product in a large string of numbers
1302 Solvers
-
Back to basics 22 - Rotate a matrix
932 Solvers
-
Generate N equally spaced intervals between -L and L
941 Solvers
More from this Author30
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!