structure to array

2 views (last 30 days)
Trader
Trader on 2 Apr 2012
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!

Answers (1)

Oleg Komarov
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.

Categories

Find more on Data Types 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!