How to plot the range at a certain value across multiple arrays?
Información
La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.
Mostrar comentarios más antiguos
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 comentarios
dpb
el 17 de Abr. de 2018
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
el 17 de Abr. de 2018
dpb
el 17 de Abr. de 2018
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
el 17 de Abr. de 2018
dpb
el 17 de Abr. de 2018
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
el 17 de Abr. de 2018
dpb
el 18 de Abr. de 2018
"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
el 18 de Abr. de 2018
Stephen23
el 18 de Abr. de 2018
@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:
Respuestas (1)
Vaibhav Gupta
el 18 de Abr. de 2018
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.
La pregunta está cerrada.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!