how not to be read the cells with zero values.
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi I have matrix A. This matrix has 1000 rows and 1000 column. many cells of this matrix have 0 as their values.I have to enter this matrix into a loop. this loop starts with:
for i=1:1000
for j=1:1000
....
.....
end
I want in this movement cells that have zero value not to be read. but when I write for i=1:1000 and for j=1:1000 these cells will be read then will be rejected. I hope I can explain my question.
Thank you
0 commentaires
Réponses (1)
Image Analyst
le 21 Nov 2015
For example
[rows, columns] = size(A);
for column = 1 : columns
for row = 1 : rows
if A(row, column) ~= 0
% Do something ONLY if the value is not zero.
end
end
end
There are vectorized ways to do things but it depends on exactly what you want to do if the value is non-zero.
5 commentaires
Image Analyst
le 22 Nov 2015
First, let's start using correct terminology. They are not "cells" like Excel calls them - they're "elements". "Cells" are a different beast entirely and I very much recommend you learn about them from the FAQ: http://matlab.wikia.com/wiki/FAQ#What_is_a_cell_array.3F
What do you want to do? Do you want to compact the array be squeezing it together to get rid of ows and columns from a 3D array where all the elements along the third dimension? You can't arbitrarily remove rows and columns from a 3D array where all the elements along the third dimension. This is because the array must remain rectangular. For example if you were to remove 3 columns from row 1 and 8 columns from row 2, now row 1 and row 2 would not have the same number of columns in them and your array is no longer rectangular - it has a ragged right edge.
Voir également
Catégories
En savoir plus sur Creating and Concatenating Matrices 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!