필터 지우기
필터 지우기

Extracting and formatting data

조회 수: 1 (최근 30일)
Doina Gumeniuc
Doina Gumeniuc 2017년 11월 19일
댓글: Doina Gumeniuc 2017년 11월 26일
Hi all,I am trying to do the following: Let's say I have two matrices
A =
2
2
1
3
B =
0.1000
0.0030
0.0500
0.0200
0.4000
0.0600
0.0900
1.0000
Every value from matrix A represents the number of values I would like to extract from matrix B. For example: if the first value in matrix A is 2, then I would like to extract first two values from B in a row [0.1,0.003] and so on.
  댓글 수: 4
Rik
Rik 2017년 11월 20일
And how did you want to save those different parts?
Doina Gumeniuc
Doina Gumeniuc 2017년 11월 21일
Hi Rik! I will fprint them into a vtk input file. In B I have numerous columns so I would like to take it column by column using the same values from A

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

채택된 답변

Walter Roberson
Walter Roberson 2017년 11월 20일
B_cell = mat2cell(B, A, size(B,2));
  댓글 수: 5
Walter Roberson
Walter Roberson 2017년 11월 26일
B_cell = mat2cell(B, A, ones(1,size(B,2)));
Doina Gumeniuc
Doina Gumeniuc 2017년 11월 26일
wow..Great, thank you a lot!

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

추가 답변 (1개)

Rik
Rik 2017년 11월 19일
A solution that might not scale well, is to convert A to a cell (with num2cell), use cellfun with @(x) 1:x, make sure it is a row array, convert back to a normal vector (with cell2mat) and use that as the index to B (so C=B(index_vector);)

카테고리

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