Info
This question is closed. Reopen it to edit or answer.
call array to vectors using a for loop error problem
1 view (last 30 days)
Show older comments
Hello
I wonder if someone can help me solve this problem:
I have a cell array named Spt < 1x1438 > and in each cell there is an array (64x5). If I run
Dir=Spt{1}(:,3);
I get a vector of Dir values. I would like to repeat this for each array within Spt so that I have 1438Dir vectors (e.g. Dir1, Dir2, Dir3,...Dir1438). Unfortunately when I run a loop I get an error:
for n=1:1438;
Dir(n)=Spt{n}(:,3);
end
??? In an assignment A(I) = B, the number of elements in B and
I must be the same.
How do I overcome this error and generate the required Dir vectors?
Thanks in advance for any advice.
0 Comments
Answers (1)
Andrei Bobrov
on 20 Apr 2011
Dir = zeros(size(Spt{1},1),length(Spt));
for n=1:length(Spt);
Dir(:,n)=Spt{n}(:,3);
end
or
Dir = cell2mat(cellfun(@(x)x(:,3),Spt,'UniformOutput' , false))
or more
S2 = cell2mat(Spt);
Dir = S2(:,3:5:length(Spt)*size(Spt{1},2));
1 Comment
Jan
on 20 Apr 2011
Or use a cell array:
Dir = cell(size(Spt{1},1), 1);
for n=1:length(Spt); Dir{n}=Spt{n}(:,3); end
This question is closed.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!