MATLAB Answers

how to remove row from 4D matlab matrix

15 views (last 30 days)
Andrew Alkiviades
Andrew Alkiviades on 30 Jul 2012
Hi I have the following 4D matrix
for idx_number_panels = 1:length(number_panels) % range of PV panel units examined
for number_turbines = 0:2 % range of wind turbine units examined
for number_batteries = 1:10 % range of battery units examined
for h=2:25 %# hours
for d = 1:number_of_days %# which day
n = h + 24*(d-1);
% hourly_deficit_1(...,..., h, d)= Demand(n)-(PV_supply(n)... %
hourly_total_RES(idx_number_panels,number_turbines + 1,number_batteries, h,d)
I want to remove the entire row every 24 rows from the above 4D matrix and thus resize the matrix. Is this possible and how can it be done since the documentation doesn't seem to help
Thanks

  0 Comments

Sign in to comment.

Answers (1)

Walter Roberson
Walter Roberson on 31 Jul 2012
Interpreting a bit about which dimension you want to remove over:
hourly_total_RES(:, :, 1:24:end, :) = [];

  4 Comments

Show 1 older comment
Andrew Alkiviades
Andrew Alkiviades on 31 Jul 2012
Walter do you mean that I then just add
testingA= hourly_total_RES(:, :, 1:24:end, :);
to my current code?
Image Analyst
Image Analyst on 31 Jul 2012
Walter's code removes those elements (which would actually be a set of 3D arrays) from the original matrix. Your code would extract those arrays from the original matrix (and leave them there) and save them in a new 4D array you create. So they are different.
You do know that when you specify one dimension of a 4D array as being a certain specific number, that you are then specifying a 3D array, not a row vector, don't you? E.g. M(:,:,42,:) is a 3D array (after you squeeze() it to get rid of the singleton dimension).
Walter Roberson
Walter Roberson on 31 Jul 2012
Only one of the dimensions can be described as being a "row".
Traditionally, MATLAB uses "row" for the first dimension, "column" for the second dimension, and "page" for the third dimension and higher dimensions. Common, though, especially in image processing, is to refer to the third dimension as "plane".
You are using h to access only the third dimension, rather than all of the dimensions, so it does not appear that you want to "remove each 24th row on each dimension".
Talking about "dimension" is like specifying a point in terms of X, Y, Z coordinates, with X being the first dimension, Y being the second dimension, and Z being the third dimension.
You can essentially think of "dimension" in this context as being which index position you are working in: A(X,:,:,:) has X in the first dimension, A(:,X,:,:) has X in the second dimension, and so on.
Ff you are referring to hourly_total_RES(:,:,h,:) and you want to remove every 24th plane (3rd dimension) then you can use
hourly_total_RES(:, :, 1:24:end, :) = [];
This will remove the first plane, the 25th plane, the 49th plane, and so on.
But your reference to 2:25 hints that what you want instead is to remove the first plane, the 26th plane, and so on, which is removing every 25th plane (leaving groups of 24) rather than removing every 24th plane (leaving groups of 23). If so, then
hourly_total_RES(:, :, 1:25:end, :) = [];
The assignment of [] to a particular plane removes that plane from the array.

Sign in to comment.

Sign in to answer this question.


Translated by