How do you find the middle column of an array in general?

1 次查看(过去 30 天)
array = [0 1 2 3 4 3 2 1 0; 0 1 2 3 4 3 2 1 0; 0 1 2 3 4 3 2 1 0;0 1 2 3 4 3 2 1 0];
%--opt 5 - Set the middle column of array2D equal to zero. If there is an
% even number of columns, set the both of the middle columns to zero. The
% floor and ceil functions are useful for this.
function [array2D] = filterAndPlot(change, opt, array2D)
if opt == 5
columnMiddle = array2D(ceil(numel(array2D) / 2.0 ))
???
So I thought you have to take the Array and divide by two, then find the numel of that and then ceil of that. Then I took the array of that and that stores the value of the element in the middle of the array. Is there a way to take that value and get the column out of that?

回答(1 个)

Image Analyst
Image Analyst 2019-4-8
Hint: use rem() to determine if the number of columns divided by 2 is an even or odd number. Then use an if statement to carry out the assignment of column(s) to zero.
  2 个评论
Image Analyst
Image Analyst 2019-4-8
No.
Plus, I don't know the point of opt5. That doesn't seem necessary at all given what you've shown.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Data Types 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by