How do you make an input variable name = ' : ' ?

1 view (last 30 days)
How do you make an input variable name = ' : ' in order to use the input name to access values in a (m x n x 3) uint8 array?
function [ new ] = array( row, col )
new(:,col,:) = []; % this only works if there are 2 :
the input variable is Row but it needs to be : so that i can delete this number in the array.
  2 Comments
James Tursa
James Tursa on 1 Sep 2015
Edited: James Tursa on 1 Sep 2015
Please provide a short example, in pseudo-code if needed, of what you would like to do. E.g., give the variables you start with, and the result you are looking for. A string variable can hold ':' of course, but that can't be the actual name of a variable.

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 1 Sep 2015
For example,
r = rand(10,5,2);
row = ':';
col = 2;
r(row,col,:) = [];
size(r)

More Answers (1)

Image Analyst
Image Analyst on 1 Sep 2015
You can't have a function that deletes a column from all planes of a 3D array if you don't pass in the array! In your function called array (a bad name in my opinion), you try to delete the column indicated by "col" from an array called "new" yet "new" does not even exist yet! Obviously, "new" must exist before you can delete things from it.
And that would not delete a number - it would delete a slice. Imagine that you have a 3D array that is a color RGB image where the indexes are (row, column, colorChannel). So you're saying to delete all rows and all colors of a particular column. So if your array was 480 rows tall by 640 columns wide, by 3 color planes high, and you wanted to delete column 42, you'd have like a vertical slice of 480 rows tall by 3 color planes high at column 42. So you'd be removing that 480 by 3 slice of values from the 3D array. That is a bunch of values, not just one value. And, like I said, that 3D array has to exist first before you can delete anything from it.

Categories

Find more on Creating and Concatenating Matrices in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!