how not to be read the cells with zero values.

6 visualizzazioni (ultimi 30 giorni)
fatema saba
fatema saba il 21 Nov 2015
Modificato: fatema saba il 22 Nov 2015
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

Risposte (1)

Image Analyst
Image Analyst il 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 Commenti
Image Analyst
Image Analyst il 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.
fatema saba
fatema saba il 22 Nov 2015
Modificato: fatema saba il 22 Nov 2015
Thank you for your patient. i know that matrix is rectangular and I can't remove some elements. Actually I don't want remove special elements but I want to decrease these repeats. I Think if I can decrease them by eliminating zero values that are common in all dimensions I can do this. I'm sorry. Thank you.

Accedi per commentare.

Tag

Non è stata ancora inserito alcun tag.

Community Treasure Hunt

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

Start Hunting!

Translated by