compensate vector into same length
1 回表示 (過去 30 日間)
古いコメントを表示
採用された回答
Stephen23
2022 年 12 月 31 日
The simplest approach is to download the function PADCAT() here:
and use it like this:
M = padcat(A,B,C)
3 件のコメント
Stephen23
2022 年 12 月 31 日
編集済み: Stephen23
2022 年 12 月 31 日
"For example, I have a loop for 4 times, within each loop I will get a vector, then I need to compensate the vector with NaN within that loop; then in next loop I will have new vector to compensate."
How will you know what length to pad to, if you do not have all of the vectors?
I suspect that you could simply store all of the vectors in a cell array, and then supply them to PADCAT after the loop. This would likely be the simplest approach:
N = 4;
C = cell(1,N); % preallocate!
for k = 1:N
V = your code that generates a vector;
C{k} = V;
end
M = padcat(C{:})
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Loops and Conditional Statements についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!