Display results in one matrix (nested for loops

1 view (last 30 days)
Hello,
I am working on my final year project, a script that detects moods/emotions generated by audio files. I am currently stuck here:
for i=1:2
for j=4:10
for k=2:3
for l=1:2
for m=1:2
X=(i,j,k,l,m);
End, end, etc.
The reason for this is that each element i,j,k,l,m of the array has several values (i.e. i is 1 or 2, j is 4 through 10 etc.)
Now the problem: I get each possible array in a single line, is there any way to store all of them in a single matrix?
Thank you in advance!
M.
  2 Comments
Salaheddin Hosseinzadeh
Salaheddin Hosseinzadeh on 14 Apr 2014
I guess it's
X(i,j,k,l,m)=someting
it won't be a bad idea to correct your code.
You said you want it all in one matrix! Well, they are in one matrix as far as I understand! X is a matrix and apparently that's where you wanna save different values!
Your question is vague!
Mihnea
Mihnea on 14 Apr 2014
No, because of the for loop, it displays each value in the same vector with 5 elements and it prints it out for every iteration of the loop. I am looking to collect these iterations in one big 5 by n matrix.
Sorry if I'm being vague, I'm trying to work on a train full of people...

Sign in to comment.

Accepted Answer

Mischa Kim
Mischa Kim on 14 Apr 2014
Edited: Mischa Kim on 14 Apr 2014
Mihnea, you probably want
X(i,j,k,l,m) = ...
For large matrices you might want to pre-allocate memory:
X = zeros(2,10,3,2,2);
  6 Comments
Vasilis Mitropoulos
Vasilis Mitropoulos on 29 Sep 2019
Thanks Mischa Kim, so simply and beautifully resolved what I wanted:)
Have a beautiful day!!!!!!!!!

Sign in to comment.

More Answers (0)

Products

Community Treasure Hunt

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

Start Hunting!