structure to array
1 view (last 30 days)
Show older comments
I'm looking to write values stored in an structure to an array like this:
p_start = 20;
p_end = 400;
p_diff = p_end - p_start;
x = 1;
s.test1 = zeros(p_diff,1);
s.test2 = zeros(p_diff,1);
s.test3 = cell(p_diff,1);
t_array = cell(p_diff,3);
for i=p_start:1:p_end
t_array(x,:) = {s.test1(i) s.test2(i) s.test3.(i)};
x = x+1;
end
is it possible to fill t_array without having to go through a loop?
Thanks for your help!
0 Comments
Answers (1)
Oleg Komarov
on 2 Apr 2012
In this case no, and you have to use:
for i = 1:p_diff
t_array(i,:) = {s.test1(i) s.test2(i) s.test3{i}};
end
If you try to describe why are you creating test1 and test2 etc... and what you wanna do next we can try to come up with loopless solution.
0 Comments
See Also
Categories
Find more on Structures 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!