Extracting and formatting data
Ältere Kommentare anzeigen
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 Kommentare
Walter Roberson
am 19 Nov. 2017
The 2 that is the second value of A: is that also to extract the first two elements of B, or is it to extract the next two elements of B ?
Doina Gumeniuc
am 20 Nov. 2017
Rik
am 20 Nov. 2017
And how did you want to save those different parts?
Doina Gumeniuc
am 21 Nov. 2017
Akzeptierte Antwort
Weitere Antworten (1)
Rik
am 19 Nov. 2017
0 Stimmen
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);)
Kategorien
Mehr zu Cell Arrays finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!