필터 지우기
필터 지우기

How to extract complex cell data into a new variable?

조회 수: 6 (최근 30일)
Austin Sowers
Austin Sowers 2018년 9월 17일
댓글: Austin Sowers 2018년 9월 17일
I have a variable with 2000 columns. In each of the 2000 columns, there is a 1x13 cell. Within each 1x13 cell, there is a varying size double (Nx1), where N is any number. I would like to have the very 1st number within the (Nx1) double, in each of the 1x13 cells, for all 2000 columns. I would like this to result in a new cell variable with 13 columns of double 2000x1 data sets. i.e. (2000x1 double, 2000x1 double, 2000x1 double, 2000x1 double, 2000x1 double, 2000x1 double, 2000x1 double, 2000x1 double, 2000x1 double, 2000x1 double, 2000x1 double, 2000x1 double, 2000x1 double,).
Because this is kind of confusing, I attached my code so you can open the variable yourself. To run it, it needs nodes.txt and pipes.txt. The variables name after you run the code, is "H"

채택된 답변

Rik
Rik 2018년 9월 17일
Using a double loop to accomplish this is still reasonably fast:
%generate a random H
s1=2000;s2=13;
H=cell(s1,1);
for n=1:s1
H{n}=cell(1,s2);
for m=1:s2
H{n}{m}=rand(randi(100),1);
end
end
clc
tic
output=zeros(size(H,1),size(H{1},2));
for n=1:size(output,1)
for m=1:size(output,2)
output(n,m)=H{n}{m}(1);
end
end
O=mat2cell(output,n,ones(m,1));
  댓글 수: 3
Austin Sowers
Austin Sowers 2018년 9월 17일
Yes. If you could please correct this, I would appreciate it very much!! I am a rookie matlab guy. It is a problem I have been working on for some time and will help me a lot. Thank you again.
Austin Sowers
Austin Sowers 2018년 9월 17일
Actually, I just transposed my "H" and it worked. Thank you so much!

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

제품


릴리스

R2016b

Community Treasure Hunt

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

Start Hunting!

Translated by