Store cells into Matrix

3 次查看(过去 30 天)
sita
sita 2013-5-13
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 个评论
Jan
Jan 2013-5-13
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.

请先登录,再进行评论。

回答(3 个)

David Sanchez
David Sanchez 2013-5-13
check out for that 3D array you call variables, Is it useful for anything? This same question was answered on Friday 10th.

Yao Li
Yao Li 2013-5-13
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.

Andrei Bobrov
Andrei Bobrov 2013-5-13
[ii jj]=ndgrid(x1s,x2s);
variables = permute([ii(:), jj(:)],[3 2 1]);

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

标签

产品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by