How to plot the range at a certain value across multiple arrays?
信息
此问题已关闭。 请重新打开它进行编辑或回答。
显示 更早的评论
I am trying to write the code that will plot the change along the 16th row across all k values. M is a 26x7 matrix iterated 101 times
M = T(1:n_i , 1:n_j , 1:k);
I tried
plot(T(16,1:n_i,1:k))
-----edit
line 83 defines the matrix
edit2: let's say
M1=[a b c d ; e f g h ; i j k l]
M2=[a+n b+n c+n d+n ; etc] where each element increases over time.
And this iterates k times. Say I want to plot the change of the 2nd row [e f g h] over time. How would I do this?
9 个评论
dpb
2018-4-17
Showing us exactly what you have so we can try to reproduce, for starters.
I really can't begin to fathom what you're trying to describe, sorry...
Evan Perovich
2018-4-17
dpb
2018-4-17
More code and trouble than I'm willing to go to...show us a small example of a matrix and what you're trying to extract where we can easily play with it. Help us help you...
Evan Perovich
2018-4-17
dpb
2018-4-17
I don't know precisely what
M2=[a+n b+n c+n d+n ; etc]
means???
If something iterates, where does the new data get stored and how?
If you mean you're updating the values in M2, the only way to plot the change would be to compute the change and plot it before it is confounded into the array; after that point it's lost.
Evan Perovich
2018-4-17
dpb
2018-4-18
"Each matrix (M1, M2.... M101)..."
There's your problem. See the Wiki FAQ on why not to create serially-named variables and how to avoid them... <Create variables A1 A2 ....>
Evan Perovich
2018-4-18
Stephen23
2018-4-18
@Evan Perovich: acessing variable names dynamically is slow, complex, buggy, and hard to debug. It obfuscates the code intent and makes code insecure. Rather than trying to access variable names in a loop you should simply put all of your data into one array, and accessing it using indexing. Indexing is simple, neat, extremely efficient, and easy to debug (unlike what you are trying to do). Read this to know more:
回答(1 个)
Vaibhav Gupta
2018-4-18
Hi, I don't know if dpb's comment solved your problem but if you are still using,
M = T(1:n_i , 1:n_j , 1:k);
You can use 'permute' command. In case of 2D data, MATLAB uses columns as data. So, we switch iterations to represent rows and required data as columns.
L = permute(M,[3,2,1]); plot(L(:,:,16)); % This would plot the 16th row of M as function of iterations
P.S. - This is my first answer. So, if I missed anything, please tell me.
0 个评论
此问题已关闭。
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!