Question

Now first off, I am not even sure this is called a matrix, and I am new to MATLAB. But let's say I have a "matrix" that looks like this:

for n=1:10
...
someImage = mat(:,:,n) %The "matrix"
...
end

where n could be the frames in a video, for example, and the first 2 ':' are the row and column data for the 2D image (the frame).

If I only wanted the first ':' of data (the row? column? element?), how would I access only that?

Intuitively, I think something like:

row1 = mat(:,0,0)
row2 = mat(0,:,0)
row3 = mat(0,0,:)

but that doesn't seem to be working.

P.S. I know that these aren't really rows, the terminology for all this would also be greatly appreciated

Also, it may not have anything to do with this, but I am using a MATLAB GUI as well, and the "matrix" is stored like this:

handles.mat(:,:,n)

I don't think it has anything to do with my actual question, but it might so I will put it here

-Thanks!

Was it helpful?

Solution

One point I would like to make before starting: MATLAB starts indexing at 1, and not 0. This is a common mistake that most people who have a C/Java/Python programming background make going into MATLAB.

Also, by doing:

row1 = mat(:,1,1);

This accesses all of the rows for the first column and the first frame of your video. Be aware that this will produce a M x 1 vector, where M denotes the number of rows for a frame in your video.

Also:

row2 = mat(1,:,1);

This accesses all of the columns in the first row of the first frame. Be aware that this will produce a 1 x N vector, where N denotes the number of columns for a frame in your video.

Also:

row3 = mat(1,1,:);

This accesses all of the pixels in the entire video sequence at row 1 and column 1. You can think of this as a temporal slice at the top left corner of your video sequence. Be aware that this will produce a 1 x 1 x T vector, where T is the number of frames in your video. If you access just a single pixel location in your video, the first two dimensions are superfluous, and so you can use the squeeze command to shrink all of the singleton dimensions so that it simplifies to a T x 1 vector. In other words, do this:

row3 = squeeze(mat(1,1,:));

FWIW, you do have the right terminology. Rows and columns are used in image / video processing all the time. As for the "matrix", you can call this a temporal sequence or a frame sequence in terms of video processing. It certainly is a 3D matrix, but people in this domain denote it as either one of the two as it is really a sequence of images / frames stacked on top of each other.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top