Reshape 2D matrix to 3D using time as 3rd dimension
1 回表示 (過去 30 日間)
古いコメントを表示
Hi,
I've got a A = n x n matrix and I want to convert this 2D matrix to a 3D one using time as the third dimension. So the 3D should show how the value of all the elements in the n x n matrix changes with respect to time.
I tried using the reshape function but to no avail.
Thanks!
0 件のコメント
採用された回答
Thorsten
2015 年 10 月 28 日
If i is your related to your time and takes values 1,2,3, etc, and A is the n x n matrix at time point i, you can use:
B(:,:,i) = A;
2 件のコメント
Thorsten
2015 年 10 月 28 日
編集済み: Thorsten
2015 年 10 月 28 日
You cannot use the values of kgrid.t_array, but instead 1:numel(kgrid.t_array). Your code should look something like below, assuming that you have a function that computes your NxN matrix for every timestep:
for i=1:numel(kgrid.t_array)
t = kgrid.t_array(i); % get the ith time value
A = computeNxNmatrix(t, more parameters); %
B(:,:,i) = A;
end
その他の回答 (1 件)
Matt J
2015 年 10 月 28 日
I tried using the reshape function but to no avail.
Be more persistent. RESHAPE is the appropriate thing to use.
2 件のコメント
lmaree
2021 年 3 月 12 日
"Beyond the second dimension, the output, B, does not reflect trailing dimensions with a size of 1. For example, reshape(A,3,2,1,1) produces a 3-by-2 matrix." from the reshape documentation.
In my case, this is exactly what I need to multiply a spacial 2D matrix with a time vector. However, reshape doesn't have the functionality it seems...
参考
カテゴリ
Help Center および File Exchange で Creating and Concatenating Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!