How can I Remove a Column and add it again?
6 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hello
I want to remove first column from an Image and do some thing on Image and then add that column again. I want to remove a colum if the number of column is odd. _
The speed and Performance of solution is important for me._
Could you help me?
thanks
1 commentaire
Image Analyst
le 25 Juin 2015
We need an explanation of the grammar in "remove a column if the number of column is odd."
Should it say "remove any column if that column number is odd." In other words, do you want to remove columns 1,3,5,7... and keep columns 2,4,6,8,...? If so, do you want the extracted columns in a new matrix, or you want to alter (make narrower) the original matrix?
Or do you mean "if the number of columns in the image is odd" in which case you'd strip off column 1 (and only column 1) if and only if the total number of columns in the image is an odd number?
Those are two different things. Your grammar makes it ambiguous so I need clarification.
Réponse acceptée
Guillaume
le 25 Juin 2015
%copy original image (img) without first column if number of column is odd
newimage = img(:, 2-mod(size(img, 2), 2):end, :);
%do something with newimage
%??
%add back first column if size is odd.
newimage = [img(:, 1:mod(size(img, 2), 2), :) newimage];
3 commentaires
Guillaume
le 25 Juin 2015
This is really basic matrix indexing.
Column 1 of a 2D or 3D matrix is:
img(:, 1, :)
The rest of the image without column one is:
img(:, 2:end, :)
You can copy these into whichever variable you want, eg.:
col1 = img(:, 1, :);
allbutcol1 = img(:, 2:end, :);
and recombine them with the concatenation operators [] (or horzcat):
img2 = [col1, allbutcol1];
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!