Delete value in matrix at crescent way and rearrange
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Richard Perosa Fernandes
am 15 Apr. 2020
Kommentiert: Ameer Hamza
am 16 Apr. 2020
Hello everyone and thanks for the help.
I'm working with a 1000x1000 matrix, example:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/284757/image.png)
I want to delete the last value of the last row, and the two last values of the penultimate line, and so go on, like this:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/284758/image.png)
After this I want to bring the last value to the end of the matrix:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/284759/image.png)
And delete the column in the left (cause I bring the lat value of the raw to the right I would get: 1 columns delete for the last raw, 2 columns delete for the penultimate raw, so go on) . So if a did this with the last 500 rows. I would get a 500x500 matrix. Someone have a though about how to begging this script?
Short example: 8x8
...
1 2 3 4 5 6 7 8
1 2 3 4 5 6 7 8
1 2 3 4 5 6 7 8
1 2 3 4 5 6 7 8
Response: 4x4
..
1 2 3 4
2 3 4 5
2 3 4 5
4 5 6 7
0 Kommentare
Akzeptierte Antwort
Ameer Hamza
am 15 Apr. 2020
Bearbeitet: Ameer Hamza
am 15 Apr. 2020
For you short example:
x = [1:8; 1:8; 1:8; 1:8];
n = 4;
new_x = zeros(n);
for i=1:4
new_x(:,i) = diag(x, i-1);
end
Result:
new_x =
1 2 3 4
2 3 4 5
3 4 5 6
4 5 6 7
2 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Dimensionality Reduction and Feature Extraction finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!