Info

This question is closed. Reopen it to edit or answer.

How to plot the range at a certain value across multiple arrays?

1 view (last 30 days)
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 Comments
Stephen23
Stephen23 on 18 Apr 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:

Answers (1)

Vaibhav Gupta
Vaibhav Gupta on 18 Apr 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.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!