Creating vectors from columns of a matrix

6 Ansichten (letzte 30 Tage)
Roy
Roy am 13 Mai 2023
Kommentiert: Roy am 13 Mai 2023
I have a matrix containing indices of elements for example:
A = [55 59; 242 270]
How can I create a matrix that has rows starting at the first element and ending at the second element of each row of A, i.e. :
B = [55 56 57 58 59; 242 243 ... 269 270]

Akzeptierte Antwort

Dyuman Joshi
Dyuman Joshi am 13 Mai 2023
You can not obtain the output you want in terms of numeric data type due to size mismatch for vertical concatenation. You can obtain the output in terms of cell arrays -
A = [55 59; 242 270]
A = 2×2
55 59 242 270
out = arrayfun(@(x) A(x,1):A(x,2), 1:size(A,1), 'UniformOutput', false)'
out = 2×1 cell array
{[ 55 56 57 58 59]} {[242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270]}

Weitere Antworten (0)

Kategorien

Mehr zu Matrices and Arrays finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by