Store cells into Matrix
2 views (last 30 days)
Show older comments
Hi, In below mentioned code i am trying to pair up all the elements in two matrices and trying to store in one matix.While storing overnested cells into variables matrix it does not store in proper order.Please help me in solving this . Thanks, Sita
clc;
clear;
countttest=0
p = haltonset(1) %'Skip',1e3,'Leap',1e2);
i1=1;
j1=3;
i2=1; j2=3; x1s(:,:)=p(i1:j1,:); x2s(:,:)=p(i2:j2,:); x1vals=x1s x2vals=x2s
[ii jj]=ndgrid(x1s,x2s);
overnested = arrayfun(@(x,y)[x y],ii,jj,'un',0)
celldisp(overnested)
for v2=i2:j2
for v1=i1:j1
variables(:,:,v1*v2)=overnested{v1,v2}
temp=variable
end
end
1 Comment
Jan
on 13 May 2013
If you post code, which stores the data in an improper order, it is impossible to guess, what "proper" exactly is.
Beside the actually useless clc, it would be much more important to concentrate on the problem and format the code properly. It matters for the chance to get a useful answer, if you care about the readability of your code.
Answers (3)
David Sanchez
on 13 May 2013
check out for that 3D array you call variables, Is it useful for anything? This same question was answered on Friday 10th.
0 Comments
Yao Li
on 13 May 2013
Make sure each element in the cell variable has the same dimention. Assuming raw is the cell variable (1x2),x is the destination matrix, For example,
raw={3:7,6:10};
x(:,1)=raw{1,1};
x(:,2)=raw{1,2};
Then the 2 elements in raw are stored in two columns of the matrix x.
0 Comments
Andrei Bobrov
on 13 May 2013
[ii jj]=ndgrid(x1s,x2s);
variables = permute([ii(:), jj(:)],[3 2 1]);
0 Comments
See Also
Categories
Find more on Logical in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!