How to have a vector that is obtained by discretizing a and b for each i.
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
albert Kinda
il 21 Giu 2025
Commentato: Steven Lord
il 21 Giu 2025
For example, when i=1, a(1)=1, b(1)=24; c=1 0.5 2 2.5 up to 24. Then we move on to i=2
0 Commenti
Risposta accettata
Chuguang Pan
il 21 Giu 2025
a=[1 2 3 4 5 6 7 8 9 10 11 12];
b=[24 23 22 21 20 19 18 17 16 15 14 13];
stepHalfFun = @(start,stop) start:.5:stop;
res = arrayfun(stepHalfFun,a,b,'UniformOutput',false)
3 Commenti
VBBV
il 21 Giu 2025
a=[1 2 3 4 5 6 7 8 9 10 11 12];
b=[24 23 22 21 20 19 18 17 16 15 14 13];
stepHalfFun = @(start,stop) start:.5:stop;
res = arrayfun(stepHalfFun,a,b,'UniformOutput',false).' % transpose
Steven Lord
il 21 Giu 2025
Another question how to transform it in matrix with 12 line ?.
In MATLAB, arrays in MATLAB cannot be "jagged" -- all the rows have to have the same number of columns. [There is an exception for arrays of Java objects under certain circumstances, I think.] So you can't have a matrix where one row has 2 elements and one has 1 element. You could pad it with NaN values or find some other padding value.
A = [1 2; 3 NaN] % works
Note that without the NaN, this wouldn't work. I left this commented out so I could run the rest of the code in this answer.
% B = [1 2; 3] % would not work
C = {[1 2], 3, 4:6}
Determine the maximum length of the data stored in cells in C.
lengthOfVectorsInCell = cellfun(@numel, C)
maxLength = max(lengthOfVectorsInCell)
Create the padding function that will pad each cell to that maximum length, filling in the newly added elements with NaN.
paddingFunction = @(x) paddata(x, maxLength, FillValue = NaN);
Apply the padding function to the cell array.
paddedC = cellfun(paddingFunction, C, UniformOutput = false)
Now that the vectors in the cell array are the same length, they can be concatenated.
D = vertcat(paddedC{:})
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Matrices and Arrays in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!