필터 지우기
필터 지우기

How to create n arrays from a mxn matrix using mat2dataset

조회 수: 1 (최근 30일)
Gaspar Cid
Gaspar Cid 2016년 6월 17일
댓글: Gaspar Cid 2016년 6월 20일
Hi guys,
I'm using mat2dataset on a 100x100 matrix and i want to create 100 arrays of each column of the dataset. This is what i'm doing:
% y=100x100 matrix
s=mat2dataset(y);
y1=(ds.y1);
y1=y1.';
y2=(ds.y2);
y2=y2.'; ... %and so on
There must be a way to do this avoiding writing every single array!
Hope you can help me
Thanks!

채택된 답변

Steven Lord
Steven Lord 2016년 6월 17일
DON'T DO THIS.
Seriously, DO NOT DO THIS.
See question 1 in the Programming section of the FAQ for more information about why this is a Bad Idea. Dynamic field names (described in the FAQ question) work for dataset arrays just like they do for struct arrays, if I remember correctly.
  댓글 수: 5
Steven Lord
Steven Lord 2016년 6월 20일
You don't need to use a dataset here. Just use a for loop iterating over the columns of y, and store the results of each iteration through the for loop in an element of the cell arrays u, v, and w.
y = randi(10, 1, 20);
C = cell(1, 20);
for k = 1:20
C{k} = magic(y(k));
end
C is a cell array whose nth cell contains the magic square matrix of size y(n) [or a specific 2-by-2 matrix if y(n) is 2, even though that matrix doesn't satisfy the requirements to be a magic square.]
Gaspar Cid
Gaspar Cid 2016년 6월 20일
Al'right! I finally did this:
u = cell(1,200);
v= cell (1,200)
w=cell(1,200)
for k=1:200
[u{k} v{k} w{k}] = yang(x0,y0,z0,a,A,P_G,mu,nu,theta,phi,x,y(k),z)
end
And it seems to work! Thank you very much!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

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