sai
sai

Reputation: 7

How to remove last n elements of a matrix in matlab?

I have a matrix of order 363 X 726. Now I wanted to remove last 1394 elements in column-major format so that I can rearrange it into 512 X 512 matrix using MATLAB. Simply put, I want to perform the reversal of the operations seen in my previous question: How to resize an image by adding extra pixels using matlab. How can I do this in MATLAB?

Upvotes: 0

Views: 1129

Answers (2)

rayryeng
rayryeng

Reputation: 104503

Assuming your matrix you want to operate on is called B, you could also just do B = reshape(B(1:512*512), 512, 512);. No need for a temporary variable and the removal of the last 1394 elements is implicit with the indexing.

Upvotes: 3

Sardar Usama
Sardar Usama

Reputation: 19689

A = rand(363,726);        % matrix of random elements with size 363x726 
A(end-1393:end)=[] ;     % removing last 1394 elements
A = reshape(A,[512 512]); % Rearranging it into 512 rows and 512 columns

Upvotes: 2

Related Questions