Convert rows an columns of 4D matrix into 2d matrix with rows and columns as index Ai_j
1 次查看(过去 30 天)
显示 更早的评论
I have a matrix of radii' a=zeros(m,2^(m-1),n(1),it+1) and expressed as a(ii,jj,mm,j).
ii is the layer number,
jj is the row number,
mm is axial iteration index
j represents the time iteration.
How can I replicate the matrix a to the form ai_j(mm,j) with layers and rows as symbolic indeces. This would optimize the iterative process of my code and would be able to plot rows the matrix ai_j(mm,j) over a single loop over i and j.
I appreciate any suggestions or leads.
2 个评论
Stephen23
2020-9-11
编辑:Stephen23
2020-9-11
"This would optimize the iterative process of my code..."
I doubt that it would optimize much. More likely the opposite would be the case.
"... and would be able to plot rows the matrix ai_j(mm,j) over a single loop over i and j."
Anything you can do with pseudo-indices in the variable name you can do better** with actual indices.
** better in the sense neater, simpler, faster, more efficient, less liable to bugs, easier to debug.
采纳的回答
Stephen23
2020-9-11
编辑:Stephen23
2020-9-11
You will get an error because plot accepts matrices only (i.e. 3rd and higher dimensions must be scalar), but apparently you are providing an array with a non-scalar 3rd dimension.
m = permute(a(2,1,x,1),[3,4,1,2]);
plot(m,...)
2 个评论
Stephen23
2020-9-11
"...whether this is the optimal option if I am trying to plot at several instantaneous times..."
That depends on factors that we don't know about: the size of the array, how much memory you have, how many times you need to plot the data, what else you are using the array for, etc.
You could permute the array once and switch around the indexing to suit, which might be more efficient:
b = permute(a,[3,4,1,2]);
plot(b(x,1,2,1))
...
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!