How to have a vector that is obtained by discretizing a and b for each i.
1 回表示 (過去 30 日間)
古いコメントを表示
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 件のコメント
採用された回答
Chuguang Pan
2025 年 6 月 21 日
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 件のコメント
VBBV
2025 年 6 月 21 日
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
2025 年 6 月 21 日
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{:})
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Matrices and Arrays についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!