Info
Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.
How to loop three functions for a cell of 30 matrix?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Hello everyone,
I am trying to create a matrix of dim. 521x30 but I need a loop that help me to create a matrix 520x30 doing the same operation for each cell of the cell "A". What I am doing without the loop is this:
I have this cell "A" 30 cells with matrices of dimension 520x1.
I use the matrix because in this way I can apply the functions I need, then:
B = cell2mat(A);
C = B(520:-20:1);
C = flip(C)';
C = repelem(C,20);
In this way I obtain the result I need but only for the first column of matrix "B" (the first cell of "A"). What I need is the same operation but for each column of "B" (cell of "A").
I could continue doing this:
D = B(520:-20:2);
D = flip(D)';
D = repelem(D,20);
E = B(520:-20:3);
E = flip(E)';
E = repelem(E,20);
....
.... until the last column of matrix "B". Obviously, this is a waste of time and line-code, but mostly it is not efficient.
Could someone help me?
Thank you in advance
2 Kommentare
Shubham Gupta
am 2 Sep. 2019
Why don't you simply do the repetition at once ? Something like this:
B = cell2mat(A); % 520x30 array
C = B(20:20:end,:); % Shortened array
C = repelem(C,20,1); % Rows repeated 20 times and columns only 1 time
You will get C as the required output but stored in one matrix. If you want these separate, you can use indexing to call them separately.
I hope it helps !
Antworten (0)
Diese Frage ist geschlossen.
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!